执行代码:
<?php
$a=[4,5,6,7];
foreach ($a as $k=>&$v){
var_dump($a);
echo "<br/>";
}
echo "<br/>";
foreach ($a as $k=>$v){
print_r($a);
echo "<br/>";
}
echo "<br/>";
print_r($a);
执行过程和结果:
array(4) { [0]=> &int(4) [1]=> int(5) [2]=> int(6) [3]=> int(7) }
array(4) { [0]=> int(4) [1]=> &int(5) [2]=> int(6) [3]=> int(7) }
array(4) { [0]=> int(4) [1]=> int(5) [2]=> &int(6) [3]=> int(7) }
array(4) { [0]=> int(4) [1]=> int(5) [2]=> int(6) [3]=> &int(7) }
Array ( [0] => 4 [1] => 5 [2] => 6 [3] => 4 )
Array ( [0] => 4 [1] => 5 [2] =&