note 36302 deleted from language.types.array by didou

From: Date: Sat, 04 Oct 2003 10:17:13 +0000
Subject: note 36302 deleted from language.types.array by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57799@lists.php.net to get a copy of this message
Note Submitter: f.kuijpers3@chello.nl ---- <?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.

« previous php.notes (#57799) next »