Send an array from a form then parse it back with PHP

Lets say we want to send an array within a form and also retrieve this array by php.

Here is a solution:

<?php
if(isset($_POST['myary']))
{
	$arrayVal = unserialize(base64_decode($_POST['myary']));
	echo '<pre>'; print_r($arrayVal); echo '</pre>';
}

//$a = array('blah' ,'blah1' ,'blah2') ;
$a = array('a'=>'blah', 'b'=>'blah1', 'c'=>'blah2') ;
$ary = base64_encode(serialize($a));
?>

<form name="form1" id="form1" action="" method="post">
	<input type='hidden' name='myary' value="<?php echo $ary ;?>" >
	<input type="submit" name="press" />
</form>

I found this solution from here.

Advertisements

1 thought on “Send an array from a form then parse it back with PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s