I'm facing some strange behavior with the array_shift function in PHP:
function shift($arr)
{
array_shift($arr);
}
$a = [1, 2, 3];
shift($a);
print_r($a);
Output:
Array ( [0] => 1 [1] => 2 [2] => 3 )
My Expected Output:
Array ( [0] => 2 [1] => 3 )
Explanation:
I believe that $a and $arr, despite being different references, point to the same array object. I expect array_shift to look where $arr is pointing and modify (shorten) that array. Then that change will be visible when looking up the array via $a.
However, when I test my theory, no change is visible. The array is just as long as before array_shift was called. What gives?