Have a weird one:
This code outputs "345":
$a = array(1,2,3,4,5);
foreach ($a as $key => $input)
{
$ab = next($a);
echo $ab;
}
But this code outputs "2345":
$a = array(1,2,3,4,5);
$abc = $a;
foreach ($a as $key => $input)
{
$ab = next($a);
echo $ab;
}
The only difference between the two codes, is that in the 2nd example the array $a was duplicated into array $abc (line 2)
Does that affect the internal pointer of the array, and how?
What is the the expected behavior?
It is all dependent on which PHP version you are running:
Anything lower than 7 will output 345
while version 7 will output 2345
You can test Here