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.

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

Leave a reply to Rafiq Cancel reply