|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10203 allow foreach($array as list($a,$b)
Submitted: 2001-04-06 06:53 UTC Modified: 2012-09-21 12:40 UTC
Avg. Score:3.7 ± 1.0
Reproduced:16 of 18 (88.9%)
Same Version:9 (56.2%)
Same OS:9 (56.2%)
From: jack at mobil dot cz Assigned: laruence (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2001-04-06 06:53 UTC] jack at mobil dot cz

foreach ($array as list($a, $b))

won't work. is there any hope this will change in future?


php-5.4.0svn-add-foreach-list-support.patch (last revision 2011-07-06 12:15 UTC by
php-5.4.0-alpha1-foreach-list-diff.patch (last revision 2011-07-06 05:34 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-06 07:19 UTC]
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 07:54 UTC] jack at mobil dot 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 $b\n";

 [2001-04-06 14:42 UTC]
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. ;)
 [2002-01-28 20:45 UTC]
foreach ($arr as $key => $val)

 [2002-01-29 03:34 UTC] jack at mobil dot cz
you haven't read the previous posts, have you?

I think it's a general problem with list() construct, that you cannot use it everywhere you can use an L-value (or however you guys call it in PHP)
 [2002-01-29 04:19 UTC]
It's in TODO already :)
Someone might implement it, but I guess it's not anytime soon.
 [2010-12-01 16:08 UTC]
-Package: Feature/Change Request +Package: Scripting Engine problem -PHP Version: 4CVS, 5CVS (2004-04-13) +PHP Version: *
 [2011-07-06 01:34 UTC]
The following patch has been added/updated:

Patch Name: php-5.4.0-alpha1-foreach-list-diff.patch
Revision:   1309930450
 [2011-07-06 01:35 UTC]
I am working on this now, add firsh patch is submitted.
 [2011-07-06 08:15 UTC]
The following patch has been added/updated:

Patch Name: php-5.4.0svn-add-foreach-list-support.patch
Revision:   1309954555
 [2011-07-06 11:20 UTC]
-Status: Analyzed +Status: Assigned -Assigned To: +Assigned To: laruence
 [2011-08-19 11:57 UTC]
-Status: Assigned +Status: Suspended
 [2011-08-19 11:57 UTC]
since the RFC didn't win the vote, change the status to suspended.
 [2011-08-19 12:08 UTC]
-Status: Suspended +Status: Wont fix
 [2012-07-19 07:17 UTC]
-Status: Wont fix +Status: Open
 [2012-09-21 12:40 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

Implemented in php-trunk.
 [2012-09-21 12:40 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 06:01:34 2024 UTC