如何在 PHP 中检查对象是否为空? [英] How to check that an object is empty in PHP?

查看:49
本文介绍了如何在 PHP 中检查对象是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 PHP 中查找对象是否为空.

How to find if an object is empty or not in PHP.

以下是 $obj 保存 XML 数据的代码.如何检查它是否为空?

Following is the code in which $obj is holding XML data. How can I check if it's empty or not?

我的代码:

$obj = simplexml_load_file($url);

推荐答案

可以强制转换为数组,然后检查它是否为空

You can cast to an array and then check if it is empty or not

$arr = (array)$obj;
if (!$arr) {
    // do stuff
}

这篇关于如何在 PHP 中检查对象是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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