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

From: Date: Sat, 07 Apr 2001 03:57:02 +0000
Subject: Re: Nested for() loops? -> Now Multi Dimension Arrays
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-47540@lists.php.net to get a copy of this message
Simple to fix it. You just need to resolve ambiguity with {}. > $res = $i * $j; > $target_array[$i][$j] = $res; > print("result = $target_array[$i][$j] <br>"); print("result = {$target_array[$i][$j]} <br>"); Regards, -- Yasuo Ohgaki <jvoth@mobiltex.com> wrote in message news:3ACDFA5B.C5BAF7C1@mobiltex.com... > > > 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>"); 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#47540) next »