Pass array through POST method
How to pass an array using POST method.
First use the function json_encode() to encode the array. Then use htmlspecialchars() to avoid errors caused by the quotes in json. Just like the following code:
echo '<input type="hidden" name="array" value="'.htmlspecialchars(json_encode($array)).'">';
To obtain the array do the inverse operation. First decode using htmlspecialcharsdecode() and then use jsondecode() to build the original array.
$array = json_decode(htmlspecialchars_decode($_POST['$array']));
More info:
http://stackoverflow.com/questions/4237090/how-to-pass-array-through-hidden-field
Written by Miguel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#