I am trying to iterate through a simple php array, and have run into bizarre behavior that is causing iteration to terminate early. My php version is 5.6.3.
The following code prints the numbers 1 through 5, as expected...
$values = array(1, 2, 3, 4, 5);
foreach ($values as $v)
//$temp_variable = $v;
echo "v: " . "$v" . "\n";
However, if I uncomment the line with the temporary variable, like so, we only get one iteration!
$values = array(1, 2, 3, 4, 5);
foreach ($values as $v)
$temp_variable = $v;
echo "v: " . "$v" . "\n";
This seems extremely bizarre. How could the act of creating an unused temporary variable cause our loop to go off-the-rails? Any advice would be appreciated, thank you!