foreach的参数不是数组:Warning: Invalid argument supplied for foreach

简介: Warning: Invalid argument supplied for foreach() 问题Warning: Invalid argument supplied for foreach() in 完善解决方案将报错的语句做如下修改(例):把QUOTE:foreach($extcredits...
Warning: Invalid argument supplied for foreach() 
问题Warning: Invalid argument supplied for foreach() in 完善解决方案
将报错的语句做如下修改(例):



QUOTE:
foreach($extcredits as $id => $credit)
{
if($credit['ratio'])
{
$exchcredits[$id] = $credit;
}
}

改为

QUOTE:
if(is_array($extcredits)) //add
{
foreach($extcredits as $id => $credit)
{
if($credit['ratio'])
{
$exchcredits[$id] = $credit;
}
}
} //add



QUOTE:
foreach((array)$extcredits as $id => $credit)
{
if($credit['ratio'])
{
$exchcredits[$id] = $credit;
}
}
造成这个错误的原因多数是因为论坛升级、编码转换造成的!
如果对PHP熟悉的人,可以直接找到出错的地方,分析出错信息是对哪个数据库表操作时造成的(一般都是论坛的基本数据表),然后,找到相应表的原版数据导进去,问题可解决。
如果对PHP不熟悉的人,可以按出错信息提示的位置,用2楼的修改方法进行修改,问题可解决。
如何联系我:【万里虎】www.bravetiger.cn 【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起) 【博客】http://www.cnblogs.com/kenshinobiy/
目录
相关文章
|
8天前
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
|
2月前
报错:cannot read properties of undefined(reading ‘forEach‘)
报错:cannot read properties of undefined(reading ‘forEach‘)
报错:cannot read properties of undefined(reading ‘forEach‘)
|
4月前
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
|
5月前
|
JSON 小程序 API
小程序踩坑-Setting data field "list" to undefined is invalid.
小程序踩坑-Setting data field "list" to undefined is invalid.
120 0
|
5月前
|
数据可视化 数据处理
解决 FAILED: UDFArgumentException explode() takes an array or a map as a parameter 并理解炸裂函数和侧视图
解决 FAILED: UDFArgumentException explode() takes an array or a map as a parameter 并理解炸裂函数和侧视图
34 0
|
6月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
52 0
TypeError: sequence item 0: expected string, int found
TypeError: sequence item 0: expected string, int found
解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题