Re: Passing an array as a hidden variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Fri, May 11, 2007 11:53 pm, Todd Cary wrote:
> When I use the following syntax, the 2 dimensional array loses
> it's contents.  Can an array be passed this way?
>
>    <? echo '<input type="hidden" name="attend_ary_save" value=' .
> $attend_ary_save .'>'; ?>

No.

You'll just get "Array" back.

You can do a few things:

<?php
  foreach($attend_ary_save as $k1 => $v1){
    foreach($v1 as $k2 => $v2){
      ?><input type="hidden" name="attend_ary_save[<?php echo
$k1?>][<?php echo $k2?>]" value="<?php echo $v2?>" /><?php
    }
  }
?>
Actually, you should wrap htmlentities() around each value being
echo-ed out.

Another option is to http://php.net/serialize the data before you send
it to HTML, and then (duh) unserialize it when it comes back.

Or, be REALLY smart, and use session_start() and just put the array in
$_SESSION and don't send data back-n-forth over HTTP, which is A)
expensive, and B) subject to user tampering, and C) inefficient.

Actually, A and C technically depend on your bandwidth versus hard
drive speed, or wherever you store you session data, so, in theory, it
could be cheaper or more efficient to use HTTP...  But I sure doubt it
in any real world hardware setup.

PS Just FYI, internally, PHP's session data is just serialized the
same way you'd do it for HTTP.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux