> Can arrays be passed to functions just like a simple variable?


> Can arrays be passed as values in hidden form fields just like a
> simple variable?

Yes, with a little work.

> I've been playing around with these and getting inconsistent 
> results.  I've been trying things like serialize and urlencode, 
> but still haven't worked out a straightforward 'rule' or policy.

For example:

  $arr = array('color' => 'red', 'fruit' => 'apple');

  $str_arr = urlencode(serialize($arr));

  <input type="hidden" name="foo" value="<?php echo $str_arr ?>">

And in the action script, do:

  $arr = unserialize(stripslashes($_REQUEST['foo']));


  a) stripslashes may be needed, in case magical quotes 
     get in the way (magic_quotes_gpc).
  b) am using $_REQUEST, you may use $_GET or $_POST or 
     whatever contains the form value.
  c) hidden, text, textarea ... doesn't matter.
  d) a way to test if what _should_ be an array 
     is really an array is with print_r() and/or 
     is_array().  print_r($arr);
  e) we don't need urldecode() because that'll 
     happen automatically when going through the form.
  f) you could use implode() instead of serialize too.

> Can someone throw some light on this? 

I hope so :)

Philip Olson

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to