I'm trying to pass an array trough a html-form input field. Using serialize to pass it and then unserialize to read the array again. I have multiple input fields.
$test = array('name' => 'Sander', 'type' => 'melon');
echo '<input type="hidden" name="rank[]" value="'.serialize($test).'" >';
Then If I want to unserialize it and show the data it gives an error:
$list = $_POST['rank'];
var_dump($list);
var_dump(unserialize($list[0]));
You most likely need to pass the serialized string through urlencode()
before outputting.
To process it then, use urldecode()
before unserialize()
.
try
$list = urldecode($_GET['rank']);
//var_dump($list);
var_dump(unserialize($list));
$test = array('name' => 'Sander', 'type' => 'melon');?>
<form >
<input type='hidden' name='rank' value='<?php echo serialize($test);?>' >
<input type="submit" >
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With