|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8447 foreach does not take "list" for value
Submitted: 2000-12-27 20:24 UTC Modified: 2001-01-23 12:07 UTC
From: Assigned:
Status: Duplicate Package: Feature/Change Request
PHP Version: 4.0.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2000-12-27 20:24 UTC]
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))")


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-23 12:03 UTC]
duplicate of #8595
 [2001-01-23 12:07 UTC]
wrong status
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 05:01:26 2024 UTC