I have this code.
foreach ($array as &$row) {
// Do stuff to array
}
A var_dump
afterwards shows the last index (107 in this case) of the array has a reference &
.
[107]=>
&array(4) {
["foo"]=>
string(2) "bar"
}
My problem is that a follow up foreach doesn't show the last index of the array, but instead repeats the second to last index.
foreach ($array as $row) {
var_dump($row);
// When it gets to 107, it'll just show 106 again
}
Why do I see this behavior and how can I ensure that the second foreach
includes the last element of the array?