如何检查 simplexml 对象的值
我有一个简单的 xml 对象数组。我现在正在编写下面的代码,
Array
(
[ID] => 1992109
[Title] => A Equipa do MAIS
[Description] => SimpleXMLElement Object
(
)
)
如何检查此数组中的“描述”值是否存在“描述”值。
i have an array that is simple xml object. i am writing the codes below
Array
(
[ID] => 1992109
[Title] => A Equipa do MAIS
[Description] => SimpleXMLElement Object
(
)
)
now how can i check the value of Description in this array that if there is a value of Description is present or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要验证
SimpleXMLElement
对象是否具有文本值,您需要将其转换为字符串:尽管您可以直接
echo
的内容SimpleXMLElement
对象,要将其字符串值用作变量,需要对其进行类型转换。empty()
必须作用于变量1,因此元素的隐式__toString()
调用将无法像使用那样工作回声。
1从 PHP 5.5 开始,
empty()
可以测试任意表达式的结果。它不再需要变量作为其参数。To verify if a
SimpleXMLElement
object has a text value, you'll need to cast it as a string:Although you are able to directly
echo
the contents of aSimpleXMLElement
object, to use its string value as a variable requires typecasting it.empty()
must act on a variable1, so the element's implicit__toString()
call won't work as it does withecho
.1Beginning with PHP 5.5,
empty()
can test an arbitrary expression's result. It no longer requires a variable as its argument.