Req #51797 [Opn->Csd]: valid arguments for foreach
Edit report at http://bugs.php.net/bug.php?id=51797&edit=1
ID: 51797
Updated by: mike@php.net
Reported by: rc at opelgt dot org
Summary: valid arguments for foreach
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: *General Issues
PHP Version: 5.2.13
-Assigned To:
+Assigned To: mike
Previous Comments:
------------------------------------------------------------------------
[2010-05-11 22:51:41] dtajchreber@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The syntax you provided works just fine and doesn't emit a warning if
$array[$i] is an array... for example:
$array[2] = range(5, 10);
$i = 2;
foreach($array[$i] as $key => $val) echo $key . '->' . $val . PHP_EOL;
------------------------------------------------------------------------
[2010-05-11 22:39:31] degeberg@php.net
The following script works fine for me:
<?php
$array = array(
array('foo','bar'),
array('test','hello'),
);
$i = 0;
foreach ($array[$i] as $key => $val) {
echo $key . $val;
}
?>
You'll have to provide a complete script that gives unexpected/incorrect
warnings.
------------------------------------------------------------------------
[2010-05-11 18:25:31] rc at opelgt dot org
Description:
------------
When I give an array to loop through the name of the array and if the
array given
is with a key, in this case $i, should make no difference.
PHP4 didnt make a warning, PHP5 instead does.
Test script:
---------------
foreach($array[$i] as $key => $val) results in an warning message.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51797&edit=1
Thread (5 messages)