Home > php教程 > php手册 > 解决Invalid argument supplied for foreach()报错

解决Invalid argument supplied for foreach()报错

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:19:20
Original
1223 people have browsed it

问题Warning: Invalid argument supplied for foreach() in 完善解决方案

 

将报错的语句做如下修改(例):

 

 

foreach($extcredits as $id => $credit)

{

if($credit['ratio'])

{

$exchcredits[$id] = $credit;

}

}

 

改为

 

if(is_array($extcredits)) //add

{

foreach($extcredits as $id => $credit)

{

if($credit['ratio'])

{

$exchcredits[$id] = $credit;

}

}

} //add

 

 

foreach((array)$extcredits as $id => $credit)

{

if($credit['ratio'])

{

$exchcredits[$id] = $credit;

}

}

 

造成这个错误的原因多数是因为升级、编码转换造成的!

 

如果对PHP熟悉的人,可以直接找到出错的地方,分析出错信息是对哪个数据库表操作时造成的(一般都是论坛的基本数据表),然后,找到相应表的原版数据导进去,问题可解决。

 

如果对PHP不熟悉的人,可以按出错信息提示的位置,用2楼的修改方法进行修改,问题可解决。

 

原文:http://www.phpweblog.net/kiyone/archive/2008/04/24/3250.aspx

 

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template