foreach ($arr as & $value) {echo ' value: '. $value. '
foreach ($arr as $value) {echo ' value: '. $value. '
?>
Output Result:
Value:one
Value:two
The first foreach with & does not change the contents of the array:
Instead of the last loop, $value references the last item in the array (you can test that the result of the second loop will not change after the first loop is unset ($value).
In your second foreach is also used by the $value variable, which creates a weird problem (you can change a variable, such as $val, the output array will not change).
The second foreach is assigned to $value, but at this point the $value is the last value of the referenced array,
So
The first loop assigns the one value to the last value,
The second assigns two to the last one,
The third and last one has been assigned to two in the second loop, so it is also two.
The above describes the PHP & value reference problem, the result of the Foreach Loop can help explain the output of the principle of what? , including the foreach aspect of the content, want to be interested in PHP tutorial friends helpful.