note 1240 deleted from language.variables.external by philip

From: Date: Mon, 01 Apr 2002 05:39:20 +0000
Subject: note 1240 deleted from language.variables.external by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28454@lists.php.net to get a copy of this message
further on assigning array through form submition (<input name="foobar[]">) Assigning a double array with this method won't work (at least not in 3.0.8). i.e. <br> in the form creation part of your page you use this code: <pre> for ($i=0;$i<5;$i++) { for ($r=0;$r<5;$r++) { echo "<input type=hidden name=\"foobar[$i][$r]\" value=\"$i|$r\">\n"; } } </pre> then try and read it back, from the form processing section, as folows; <pre> for ($i=0;$i<5;$i++) { for ($r=0;$r<5;$r++) { echo $foobar[$i][$r] . " - "; } } </pre> will return <br> - - - - (....etc)<br> no values are set, or more acuratelly, the arrays aren't assigned as one would expect. instead, use the following code in the form creation part <pre> for ($i=0;$i<5;$i++) { for ($r=0;$r<5;$r++) { echo "<input type=hidden name=\"foobar$i[$r]\" value=\"$i|$r\">\n"; } } </pre> then, in the form proccessing code, use "variable variable" assignment to retrieve the data as follows; <pre> for ($i=0;$i<5;$i++) { $myFoob = "foobar" . $i; for ($r=0;$r<5;$r++) { echo ${$myFoob}[$r] . " - "; } } </pre> which will return<br> 0|0 - 0|1 - 0|2 .... - 4|3 - 4|4 -

« previous php.notes (#28454) next »