note 36302 added to language.types.array

From: Date: Sat, 04 Oct 2003 06:20:04 +0000
Subject: note 36302 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-57795@lists.php.net to get a copy of this message
<?php for($i=0;$i<=2;$i++) { for($j=0;$j<=2;$j++) { $array[$i][$j] = $i + $j; echo "Array[$i][$j]: {$array[$i][$j]}\n"; } } ?> Why are you saying this is correct? It certainly is NOT. Try using this, and it will work too (this is the good notation) <?php $array = array( 1 => array ( 1 => 1, 2 => 2, 3 => 3 ), 2 => array ( 1 => 1, 2 => 2, 3 => 3 ) ); for ($i = 0;$i <= 2; $i++) { for($j = 0; $j <= 2; $j++) { $array[$i][$j] = $i + $j; echo "Array[" . $i . "][" . $j . "]: ".$array[$i][$j]."<br>\n"; } } /* output: Array[0][0]: 0 Array[0][1]: 1 Array[0][2]: 2 Array[1][0]: 1 Array[1][1]: 2 Array[1][2]: 3 Array[2][0]: 2 Array[2][1]: 3 Array[2][2]: 4 */ ?> You see? You should ALWAYS keep variabeles out of quotes, as it wil often deliver you errors. ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36302 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36302&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36302&report=yes Search Tool -- http://master.php.net/manage/user-notes.php

« previous php.notes (#57795) next »