Re: Passing an array as a hidden variable

From: Date: Sun, 13 May 2007 04:58:08 +0000
Subject: Re: Passing an array as a hidden variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-254865@lists.php.net to get a copy of this message
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?

« previous php.general (#254865) next »