Re: Passing arrays to forms

From: Date: Sat, 24 Jun 2000 01:33:28 +0000
Subject: Re: Passing arrays to forms
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2883@lists.php.net to get a copy of this message
> A lot of discussion seems to go toward this. > > As a result I wrote a script to see what was going on. > I haven't yet seen an explanation that I could understand for the result I got. > > I can set up an array, no problem. > I can pass the values from one php script with a form post or back to > itself, no problem. > Display those values in the same or another form, no problem. > I can strip the empty rows from a cell with array_splice, no problem. > > Problem - > What I don't seem to understand is why the size of the array always grows by > one row, and why that one row always has the value of Array. > Then if I use array_pop to shed the Array value, it turns int "A", not > "Array". > > Is this normal or am I doing something strupid in my post? You are doing something stupid. Watch: $foo = array(1,2,3); echo $foo; echo $foo[0]; This produces: Array 1 Now, if you pass $foo across a form post: <form action=next.php action=POST> <input type=hidden name=foo value="<?echo $foo?>"> </form> in next.php echo $foo; echo $foo[0]; This produces: Array A Because what you sent across is the actual string "Array" instead of the array itself. So $foo[0] becomes the first character of this string which is 'A' To send an array from one page to the next you have to send each item explicitly. eg. while(list($k,$v)=each($foo)) { echo "<input type=hidden name=foo[$k] value=\"$v\">"; } -Rasmus

« previous php.general (#2883) next »