PHP - Copying an array changes the internal pointer?
There is a strange 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 these two codes is that in the second example, the $ a array was duplicated into the $ abc array (line 2)
Does this affect the internal pointer of the array and how?
What is the expected behavior?
+3
source to share