Copy Code code as follows:
foreach ($array as & $row) {
$row = explode ('/', $row);
}
foreach ($array as $row) {
Do something
}
So to write, in the second loop there will be a logical error, add the second loop where do something is output $row, the loop to the last time the output is the penultimate element, not the last
To write that.
Copy Code code as follows:
foreach ($array as & $row) {
$row = explode ('/', $row);
}
Unset ($row);
foreach ($array as $row) {
Do something
}
Or the first loop to write that.
Copy Code code as follows:
foreach ($array as $key => $row) {
$array [$key] = explode ('/', $row);
}
say the principle.
The first loop uses the reference, and after the loop ends, the $row refers to the last element of the $array array, and when the second loop is started, $row variable is assigned a new value each time it is in PHP, if a memory space is referenced, So when you change it, you change the value of the memory space directly, that is, when the first loop of the second foreach, the value of the last element of the $array is changed to the value of the first element of the $array, and the second loop is changed to the value of the second element, When the second cycle is reversed, it is changed to the second last element value, and the value of the Enlightenment is necessarily the penultimate value of the second.
Of course, this problem does not occur if the for loop of PHP is scoped ...