为foreach提供了无效的参数! [英] Invalid argument supplied for foreach!

查看:187
本文介绍了为foreach提供了无效的参数!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为foreach()提供了无效的参数


以下代码:

 < 
foreach($格式为$ form)
{
echo $ form;
?>
< ul>
<?
$ s = $ database-> onlineFormatUsers($ form);
while($ row = mysql_fetch_assoc($ s))
{
$ username = $ row ['username'];
$ id = $ row ['id'];?>
< a href =../ userprofile.php?id =<?echo $ id?>><?echo$ username;?><一个>< /锂>
<?
}
?>
< / ul>
<?
}
?>

<?
//活动格式
$ f = $ database-> activeFormats();
while($ row = mysql_fetch_assoc($ f))
{
$ format = $ row ['name'];
}
?>

这是说它是一个无效的参数?
任何原因为什么?
谢谢

解决方案

$ format 可能不是数组。
$ b

中包含 foreach 块if(is_array($ format)){通过执行 $ format =(array)$ format


将其转换为数组

Possible Duplicate:
Invalid argument supplied for foreach()

I have the following code:

<?
foreach($format as $form)
{
    echo $form;
    ?>
    <ul>
        <?
        $s = $database->onlineFormatUsers($form);
        while($row=mysql_fetch_assoc($s))
        {
            $username=$row['username'];
            $id=$row['id'];?>
            <li><a href="../userprofile.php?id=<?echo $id?>"><?echo "$username";?></a></li>
        <?
        }
        ?>
    </ul>
    <?
}
?>

<? 
//the active formats
$f = $database->activeFormats();
while($row=mysql_fetch_assoc($f))
{
    $format=$row['name'];
}
?>

It is saying its an invalid argument? Any reason why? Thanks

解决方案

$format is probably not an array.

Wrap the foreach block in an if(is_array($format)) { } block or cast it to an array by doing $format = (array)$format.

这篇关于为foreach提供了无效的参数!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆