Home > Article > Backend Development > Dynamically add data to the array during foreach loop, foreach array_PHP tutorial
Add data (we will give you an example here)
Result:
foreach ($arr as &$v){···}, it is equal to $v=&$arr[$k]
$arr[$k] and $v At the same time, it points to the memory address of $arr[$k]. Even unset($v) only deletes the reference of $v to the memory space and does not delete the reference of $arr[$k] to the memory address, so $arr [$k] is still alive, so $arr naturally remains unchanged, so it should be like this
Result:
There is one more thing to note: &$kWhat is the result
Result:
It means: the key cannot be quoted, there is no such syntax format at all