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;
}
}

Leave a Reply

Your email address will not be published.