Edit report at http://bugs.php.net/bug.php?id=28919&edit=1
ID: 28919
Comment by: rc at opelgt dot org
Reported by: black at scene-si dot org
Summary: foreach does not take list() as argument output
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: any
PHP Version: Irrelevant
New Comment:
Why not using this code?
foreach ($table as $key=>$val) {
echo $key.":".$val[0].", ".$val[1]."\n";
}
Previous Comments:
------------------------------------------------------------------------
[2004-06-25 19:48:45] [email protected]
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.
------------------------------------------------------------------------
[2004-06-25 13:20:05] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=28919&edit=1