note 8180 added to array
| From: | bonhomme at earthling dot net | Date: | Wed, 30 Aug 2000 11:38:52 +0000 |
| Subject: | note 8180 added to array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-3655@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].
http://www.php.net/manual/function.array.php