foreach against global array not resetting
Posted: Thu Dec 10, 2009 12:30 pm
On a server running PHP 4.4, the code below prints
1123
But if I remove the global declaration it prints
1123
2123
3123
Does anyone know if this is a bug, or if it was a feature changed in later version of PHP (A server running PHP 5.2.11 gives the latter result set with or without the global declaration.
1123
But if I remove the global declaration it prints
1123
2123
3123
Does anyone know if this is a bug, or if it was a feature changed in later version of PHP (A server running PHP 5.2.11 gives the latter result set with or without the global declaration.
Code: Select all
global $testArray;
$testArray=array("1","2","3");
print "<br>Program starts<br>";
foreach($testArray as $k=>$v)
{
print "<br>Outer $v -> inner";
foreach($testArray as $kinner=>$vinner)
{
print $vinner;
}
}
print "<br><br>Program Ends";