note 8180 rejected from function.array by hholzgra
| From: | hholzgra@php.net | Date: | Sat, 02 Mar 2002 18:09:13 +0000 |
| Subject: | note 8180 rejected from function.array by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-27274@lists.php.net to get a copy of this message | ||
ATTN: caspre@yahoo.com (but possibly relevant for everyone else)
You can't declare array(array()) for 2D arrays. This actually creates an "array" with
one value, which contains an array. ie. you will be able to add data to $myarray[0][$foo] for any
value of $foo, but not $myarray[1][$foo], etc -- this data doesn't get added.
To do 2D arrays properly you must declare an array then add an array to it thus:-
$myarray = array();
array_push($myarray, array());
This doesn't work in PHP3...for PHP3 use:
$myarray = array();
$myarray[] = array();
You can still, of course, access 2D variables with $myarray[$x][$y].