php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28919 foreach does not take list() as argument output
Submitted: 2004-06-25 13:20 UTC Modified: 2013-03-15 07:07 UTC
Votes:2
Avg. Score:1.0 ± 0.0
Reproduced:0 of 2 (0.0%)
From: black at scene-si dot org Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
 [2004-06-25 13:20 UTC] black at scene-si dot org
Description:
------------
Requesting additional functionality for foreach?

Reproduce code:
---------------
$table = array();
$table['username'] = array(1,"John doe");
$table['black'] = array(2,"Jane doe");
$table['yawn'] = array(3,"Undefined");

foreach ($table as $key=>list($id,$title)) {
  echo $key.":".$id.", ".$title."\n";
}
foreach ($table as list($id,$title)) {
  echo $id.", ".$title."\n";
}

Expected result:
----------------
username:1, John doe
black:2, Jane doe
yawn:3, Undefined
1, John doe
2, Jane doe
3, Undefined

Actual result:
--------------
Parse error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-25 19:48 UTC] pollita@php.net
This is expected behavior.  list() is a left-hand language construct and not currently intended to be used this way.

Reclassifying to Feature/Change Request.
 [2010-05-11 17:39 UTC] rc at opelgt dot org
Why not using this code?

foreach ($table as $key=>$val) {
  echo $key.":".$val[0].", ".$val[1]."\n";
}
 [2010-05-12 08:39 UTC] black at scene-si dot org
-Package: Feature/Change Request +Package: *General Issues
 [2010-05-12 08:39 UTC] black at scene-si dot org
It wouldn't be a FEATURE then, would it?
 [2013-03-15 07:07 UTC] nikic@php.net
This has been implemented for PHP 5.5.
 [2013-03-15 07:07 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu May 08 11:01:27 2025 UTC