检查 stdClass 对象在 PHP 中是否有“条目”
2022-08-30 11:25:52
我有一个模型,可以检查数据库中的条目。喜欢这个:
public function getByID($id)
{
if(false == is_numeric($id))
return false;
$images = array();
$query = $this->db->where("id_album", $id)->order_by("order", "ASC")->get("images");
foreach($query->result() as $row)
$images[] = $row;
return (object) $images;
}
在我看来,我想知道我是否有行,以显示图像。我这样做:
<?php if(false != isset($content->images)): ?>
<pre><?php print_r($content->images); ?></pre>
<?php endif; ?>
但是每次我在没有结果时尝试跳过(我得到一个stdClass()空),我都失败了。我试过了。。。我不知道如何跳过“严重性:通知消息:未定义的变量”。isset
$content->images != NULL
!$content->images
提前感谢您。
更新:
$content
具有比图像更多的集,如 或 。$content->_data
$content->title
当我在数据库上没有图像并且我没有从MySQL返回时,请执行以下操作:
<?php echo count($content->images); ?>
<pre><?php print_r($content->images); ?></pre>
输出为:
1
stdClass ( )