PHP 4.0 Bug #8447: foreach does not take "list" for value

From: Date: Thu, 28 Dec 2000 01:24:38 +0000
Subject: PHP 4.0 Bug #8447: foreach does not take "list" for value
Groups: php.dev 
Request: Send a blank email to php-dev+get-42350@lists.php.net to get a copy of this message
From: david@php.net Operating system: Linux PHP version: 4.0.4 PHP Bug Type: Scripting Engine problem Bug description: foreach does not take "list" for value 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))") -- Edit Bug report at: http://bugs.php.net/?id=8447&edit=1

« previous php.dev (#42350) next »