Really not sure how to even describe this, so I'll try and let the code explain.
$numbers = [
10,
20,
30
];
foreach($numbers as &$number) {
$number = 1*$number;
}
var_dump($numbers);
foreach($numbers as $number) {
echo $number . "\n";
}
The var_dump
give the following output:
array(2) {
[0]=>
int(10)
[1]=>
int(20)
[2]=>
&int(30)
}
but looping over the same array gives:
10
20
20
When I iterate the array, why do I get the first two elements as the numbers I defined, but the third element seems to be a copy of the second element.
Why does the var_dump
have the 'expected' result, but contains a reference symbol for the third, but expected value?