Home > Article > Backend Development > Solution to foreach prompt Warning:Invalid argument supplied for foreach() under php
This article mainly introduces the solution to the foreach prompt Warning: Invalid argument supplied for foreach() under PHP. It is a problem that many developers often encounter in the process of PHP programming. Friends who need it can refer to it. Next
The example in this article describes the solution to the foreach() error message Warning: Invalid argument supplied for foreach() in php. Share it with everyone for your reference. The specific implementation method is as follows:
1. Problem:
foreach() error message under php Warning: Invalid argument supplied for foreach()
Error Tip: Warning: Invalid argument supplied for foreach() in E:wampwwwmyshopcart.php on line 95
2. Solution:
Error tip Warning: Invalid argument supplied The Chinese meaning of for foreach() is that foreach needs to be an array and an invalid parameter is given to it.
is to add a judgment in front of the loop and directly use is_array to judge whether the given value is an array. The code is as follows:
Copy code The code is as follows:
if(is_array($items) && !emptyempty($items)){ foreach( ) }
Or force conversion of data type, the code is as follows:
Copy code The code is as follows:
foreach((array)$v as $k1 => $v1) { $edu[$k1][$k] = my_h($v1);// v1是最终要入库的数据,进行转义处理 }
The above is the detailed content of Solution to foreach prompt Warning:Invalid argument supplied for foreach() under php. For more information, please follow other related articles on the PHP Chinese website!