Re: Nested for() loops? -> Now Multi Dimension Arrays

From: Date: Fri, 06 Apr 2001 17:18:19 +0000
Subject: Re: Nested for() loops? -> Now Multi Dimension Arrays
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-47474@lists.php.net to get a copy of this message
Joe Stump wrote: > > A copy and paste into foo.php and then a php -q foo.php yielded results for > me. Yeah, it's giving me results too today. I don't know what went wrong yesterday. To extend my question, I'm trying to work with multidimensional arrays. For example, I would like to do this: <? error_reporting(E_ALL); $target_array = array(); echo "starting <br>"; for( $i=0; $i<5; $i++ ) for( $j=0; $j<5; $j++ ) { $res = $i * $j; $target_array[$i][$j] = $res; print("result = $target_array[$i][$j] <br>"); } echo "done"; ?> And this is my result today: starting result = Array[0] result = Array[1] result = Array[2] result = Array[3] result = Array[4] result = Array[0] result = Array[1] result = Array[2] result = Array[3] result = Array[4] result = Array[0] result = Array[1] result = Array[2] result = Array[3] result = Array[4] result = Array[0] result = Array[1] result = Array[2] result = Array[3] result = Array[4] result = Array[0] result = Array[1] result = Array[2] result = Array[3] result = Array[4] done My thinking is that PHP ought to be like C when doing simple stuff like this. I must have something wrong with the declaration of the array. How do you declare a multidimensional array??!!?? How do you work with it then??? Thanks in advance!! John

« previous php.general (#47474) next »