Note: Unless the array is referenced, foreach operates on a copy of the specified array, not the array itself. Therefore, the array pointer will not be changed by the each() structure, and modifications to the returned array cells will not affect the original array.
1. Since php5, foreach may also traverse the properties of the object.
2. Since php5, foreach can easily modify the cells of the array by adding & before $value. This method will assign the value by reference instead of copying a value.
Copy code The code is as follows:
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
?>
Output: $arr=array(2, 4 , 6, 8)
Note: foreach does not support the ability to suppress error messages with "@".
http://www.bkjia.com/PHPjc/323085.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323085.htmlTechArticleNote: Unless the array is referenced, foreach operates on a copy of the specified array, not the array itself. . Therefore the array pointer will not be changed by the each() structure, for the returned array...