Solution to foreach prompt Warning:Invalid argument supplied for foreach() under php

不言
Release: 2023-03-24 17:24:02
Original
3785 people have browsed it

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( )  
}
Copy after login


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是最终要入库的数据,进行转义处理  
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template