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.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to