Re: language question

From: Date: Tue, 23 Oct 2001 20:40:05 +0000
Subject: Re: language question
Groups: php.general 
Request: Send a blank email to php-general+get-71992@lists.php.net to get a copy of this message
david, the syntax needs a single variable there...not a list, or multiple vars...plus, if you look at http://php.net/list, you'll see it returns void, and foreach($table as void) doesn't make much sense... jack ----- Original Message ----- From: David Otton <djo@jawbone.freeserve.co.uk> Date: Tuesday, October 23, 2001 4:14 pm Subject: Re: [PHP] language question > On Mon, 22 Oct 2001 16:47:56 +0200, you wrote: > > >On Monday 22 October 2001 14:28, David Otton wrote: > >> why does this work: > >> > >> foreach ($table as $row) > >> list ($a, $b) = $row; > >> > >> but this doesn't? > >> > >> foreach ($table as list ($a, $b)); > > > >because the correct syntax is > > foreach ($table as $key => $val) { > > ... > > } > > >RTFM :) > > Well... no. The manual says "There are two syntaxes; the second is a > minor but useful extension of the first: > > foreach(array_expression as $value) statement > foreach(array_expression as $key => $value) statement" > > Ok, let me rewrite my examples, so they're definitely not about > dictionaries : > > $table is an array of arrays. Each inner array has three values. > > Roughly.... $table = ((1,2,3),(4,5,6),(7,8,9)) > > foreach ($table as $row) > list ($a, $b, $c) = $row; > > foreach ($table as list($a, $b, $c)); > > I still don't see what it is about list() that precludes it's use in > this way. Anyone? > > >BTW: overwriting $a, $b in each iteration isn't particularly > useful... > But it is a minimal example of the construct I don't understand. > > djo > > > -- > 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 (#71992) next »