[PHP-DEV] PHP 4.0 Bug #8447 Updated: foreach does not take "list" for value From: cynic <email protected>
Date: 01/23/01

ID: 8447
Updated by: cynic
Reported By: david <email protected>
Old-Status: Closed
Status: Duplicate
Bug Type: Feature/Change Request
Assigned To:
Comments:

wrong status

Previous Comments:
---------------------------------------------------------------------------

[2001-01-23 12:03:05] cynic <email protected>
duplicate of #8595

---------------------------------------------------------------------------

[2000-12-27 20:24:38] david <email protected>
I have an array:

$a = array(0 => array(1, 2),
        1 => array(3, 4),
        2 => array(4, 5));

I want to do

foreach ($a as list($q, $r)) { }

i.e. i want the loop to return
$q = 1, $r = 2.
$q = 3, $r = 4.
$q = 5, $r = 6.

However I get

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in [blahblah]

The equivalent would be

foreach ($a as $b) {
  list($q, $r) = $b;
}

but that is unnecessarily convoluted

list() is acceptable in function return context so it seems reasonable to have it here also.

(Note: No, I don't mean "foreach ($a as $b => $c)"
I mean "foreach ($a as $b => list ($q, $r))")

---------------------------------------------------------------------------

Full Bug description available at: http://bugs.php.net/?id=8447

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>