Not sure if this is considered a bug
$array = ['numbers' => [1, 2, 3]];
foreach ($array as &$numbers) {
$numbers = [4, 5, 6];
}
var_dump($array);
modify_array($array);
var_dump($array);
function modify_array($array_arg)
{
$array_arg['numbers'] = [1, 2, 3];
}
Prints
array(1) {
["numbers"]=>
&array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}
}
array(1) {
["numbers"]=>
&array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
}
Notice that $array was not passed by reference to modify_array() however the nested array was modified. It sounds logical but not sure if this is documented!