See this foreach loop when you are familiar with the project code:
foreach($data as &$val) {
....
}
The first time I saw the loop, I used the address sign "&", and the symbol in my impression was taken directly to the address of the variable.
Then the inside of the loop operation, relatively tall on the point, such as the following example:
I now have a need to add an element to an array, often with this requirement
Commodity statistics: Commodity prices, merchandise sales quantity
The demand is to count the total revenue of the goods
$arr=Array(Array ( ' price ' => 10 , ' count ' => 100 array ( ' price ' =>20 ' count ' => 90 )
Instead of using a new array to store the results, insert the old array directly into the new array.
foreach ($arr as &$val) {
$val [' Total ']=$val[']* '$val ['count '];
}
In fact, the following code is no different:
foreach ($arr as $k = =$val) {
$arr [$k] [' Total ']= $val [']* ' $val [' count '];
}
But I think the grid may be high.
The PHP foreach Loop uses the "& $val" address character "&"