The old problem (foreach + & amp; problem) encountered during Database batch import yesterday can be summarized as: $ arr & nbsp ;=& nbsp; array, 3, 4, 5); foreach ($ arr & nbsp; as & nbsp; $ key & nbsp ;=& gt; & nbsp; & amp; $ row) & the old problem encountered during batch database import yesterday (foreach + & Problem)
The problem can be summarized as follows:
$arr = array(1,2,3,4,5);
foreach($arr as $key => &$row) {}
foreach($arr as $key => $row) {}
var_dump($arr);
array (size=5)
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => &int 4
Foreach pointer problem, pointer, please show up! Share :? & $ Row )? {} Foreach ($ arr? As? $ Ke... 'data-pics = ''>
------ Solution --------------------
$ Arr = array (1, 2, 3, 4, 5 );
Foreach ($ arr as $ key =>& $ row) {}// after this execution is complete, $ arr [4] is a reference with a value of 5
Foreach ($ arr as $ key => $ row) {}// this execution process means that the current value is assigned to $ arr [4] Each time, the value of $ arr [4] is 4 when the fourth round is completed. the fifth round is to assign a value to yourself, so it is 4.
$arr = array(1,2,3,4,5);
foreach($arr as $key => &$row) {}
var_dump($arr);
echo $arr[4].'
';
foreach($arr as $key => $row) {
echo $arr[4].'_';
}
var_dump($arr);