Jump to content

PHP array


sugan

Recommended Posts

I have an array of values and i am trying to send the array values with a hidden input field from a form to another script.How can this be done?

<input type=hidden name=array value="<?php echo $arrayname;?>">

I want to post the array values in another php page.Is this possible?Regards,Sugan

Link to comment
Share on other sites

Never tried this working with a hidden element, but i think something like this would work(make sure this is inside a form tag or something)

<?foreach($array as $value){ echo "<input type=\"hidden\" name=\"ElementArray[]" value=\"$value\" />\n";}?>

in the next page, the $_POST data would have ElementArray as an array... I think. I know it works for checkboxes. never tried it with hidden inputs.

Link to comment
Share on other sites

You can also do this:

<?php$array = array(  0 => "zero",   1 => "one",   2 => "two",   "sky" => "blue",   "grass" => "green");echo "<input type=\"hidden\" name=\"ar\" value=\"" . base64_encode(serialize($array)) . "\">";?>

<?php$array = unserialize(base64_decode($_POST['ar']));print_r($array);?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...