Home > Backend Development > PHP Tutorial > Solution to foreach prompt Warning:Invalid argument supplied for foreach() under php, foreachsupplied_PHP tutorial

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

WBOY
Release: 2016-07-13 10:14:30
Original
1136 people have browsed it

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

The example in this article describes the solution to the foreach() error message Warning: Invalid argument supplied for foreach() under PHP. Share it with everyone for your reference. The specific implementation method is as follows:

1. Question:

Foreach() error message under php Warning: Invalid argument supplied for foreach()

Error message: Warning: Invalid argument supplied for foreach() in E:wampwwwmyshopcart.php on line 95

2. Solution:

The error message Warning:Invalid argument supplied for foreach() in Chinese means that foreach needs to be an array and an invalid parameter is given to it.

Just add a judgment before 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 is the data that will eventually be stored in the database and needs to be escaped
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/909335.htmlTechArticleSolution to foreach prompt Warning:Invalid argument supplied for foreach() under php, foreachsupplied This article describes the example under php foreach() error message Warning: Invalid argument suppli...
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