Php foreach reports "Cannot create references to elements of a temporary array expression", foreachreferences
When I use the php foreach database to query results in the project today, in order to make it easy to determine whether the data exists or not, when I directly use the (array) to forcibly convert the data, the error 502 is reported when the web page cannot be opened at the beginning, suddenly, php reported "Cannot create references to elements of a temporary array expression" and found the error line. The original code is as follows:
Foreach (array) $ net_arr as $ k => & $ val) {$ network [$ val ['node _ ip'] [$ val ['ifname'] = $ val ;}
The code is changed to the following code to restore the normal operation.
If (! Empty ($ net_arr) {foreach ($ net_arr as $ k =>&$ val) {$ network [$ val ['node _ ip'] [$ val ['ifname'] = $ val ;}}
Search on the Internet, only in the http://www.laruence.com/2008/11/20/630.html [Snow Corner] blog to find a line of php source code in the error statement description, the specific reason is not detailed, record to prompt themselves to write code to be rigorous, write in one step !!!