PHP 4.0 Bug #10203 Updated: foreach weakness
| From: | torben@php.net | Date: | Fri, 06 Apr 2001 18:42:56 +0000 |
| Subject: | PHP 4.0 Bug #10203 Updated: foreach weakness | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-51067@lists.php.net to get a copy of this message | ||
ID: 10203
Updated by: torben
Reported By: jack@mobil.cz
Status: Open
Bug Type: Feature/Change Request
Assigned To:
Comments:
It's for someone else to decide whether to add this to
the language, but until they do you can achieve the same
effect with:
$arr = array(array(1, 2), array(3, 4));
foreach ($arr as $narr) {
list($a, $b) = array_values($narr);
echo "$a, $b\n";
}
BTW--it would have helped if you had explained what
results you were after and not just the syntax you wanted. ;)
Previous Comments:
---------------------------------------------------------------------------
[2001-04-06 07:54:29] jack@mobil.cz
no, 'list' should assign an array to a list of variables.
$arr = array(array(1, 2), array(3, 4));
foreach ($arr as list($a, $b))
echo "$a $bn";
---------------------------------------------------------------------------
[2001-04-06 07:19:30] hholzgra@php.net
and what should it do?
i guess you want to have key and value in one step?
this is done by the foreach($array as $key => $value)
construct, does that satisfy your needs?
---------------------------------------------------------------------------
[2001-04-06 06:53:12] jack@mobil.cz
hello
foreach ($array as list($a, $b))
;
won't work. is there any hope this will change in future?
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10203&edit=2