PHP - CodeIgniter - 为foreach()提供的参数无效 [英] PHP - CodeIgniter - Invalid argument supplied for foreach()

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

问题描述

我尝试用CodeIgniter写一个网站,但我有一个PHP的问题。我相信它是那么简单,不能错。但我不知道bugs,只是一个新手CodeIgniter:)

I try to write a site with CodeIgniter but I've a problem with PHP. I'm sure that it's so simple and can't be wrong. But I don't know bugs from , just a newbie of CodeIgniter :)

    <html>  
    <head>  
        <title><?=$page_title?></title>  
    </head>  
    <body>  
        <?php foreach($result as $row):?>  
        <h3><? echo $row->title; ?></h3>  
        <p><? echo $row->text; ?></p>  
        <?php endforeach;?>  
    </body>  
</html> 

我有一个来自此文件的错误:

I've a bug from this file :


遇到PHP错误

A PHP Error was encountered

严重性:警告


提供的参数无效foreach()

Message: Invalid argument supplied for foreach()

文件名:views / helloworld_view.php

Filename: views/helloworld_view.php

行号:6

预先感谢您阅读:)

推荐答案

您提供给foreach循环的变量必须是一个数组。如果所提供的变量的值不是具有以下解决方案的数组,则可以跳过foreach。

The variable you supply to the foreach loop has to be an array. You can skip the foreach if the value of the variable supplied is not an array with the solution below.

<?php if(is_array($result)): ?>
<?php foreach($result as $row):?>  
<h3><? echo $row->title; ?></h3>  
<p><? echo $row->text; ?></p>  
<?php endforeach;?>  
<?php endif; ?>

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

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