PHP reference traverses the array, why is the output of the last element of the array preceded by a &

topic description

traversing the array with foreach and using the & reference assignment, I can"t understand why the last value of the array element is preceded by a &

related codes

/ / Please paste the code text below (please do not replace the code with pictures)
$arr=array (1meme 2Jing 3Jing 4);
foreach ($arr as & $value) {

$value=$value*2;

}
var_dump ($arr);
? >

the running result is as follows

clipboard.png

Php
May.23,2022

because your foreach adds the & reference symbol, this variable is still valid at the end of the loop (foreach does not isolate scope) and is a reference variable

Menu