Re: language question

From: Date: Tue, 23 Oct 2001 20:14:30 +0000
Subject: Re: language question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-71989@lists.php.net to get a copy of this message
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

« previous php.general (#71989) next »