我有一个doubt.this是我的foreach循环的foreach并且这在PHP表示警告
<table>
<?php foreach($this->msg as $l): ?>
<tr><td>
<a href="index.php/downloads?id=<?php echo $l->id;?>"><?php echo $l->name;?></a>
</td></tr>
<?php endforeach; ?>
</table>
其中$这 - >信息是从数据库结果的数组。这显示警告
Warning: Invalid argument supplied for foreach()
我应该如何解决这个问题?
那时的你调用这个代码,'$这个 - > msg'是不是** ** 数组。你应该在进入循环之前检查它的类型(尝试'is_array'),或者在声明中将它实例化为一个空数组,例如'private $ msg = array();' – Phil
使用var_dump并检查$ this-msg值 –
检查$ this-> msg数组'var_dump($ this-> msg)' – vbrmnd