PHP SimpleXML检查孩子是否存在 [英] php SimpleXML check if a child exists
本文介绍了PHP SimpleXML检查孩子是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
A->b->c
可能存在,但c
可能不存在.如何检查?
A->b->c
might exist but c
might not exist. How do I check it?
推荐答案
if($A->b->c != null) //c exists
如果c
不存在,则其值将为null
(或更准确地说,它将没有值).但是请注意,要使此功能起作用,A
和b
都不必都为null
.否则,PHP会引发错误(我认为).
If c
does not exist, its value will be null
(or, to be more precise, it will have no value). Note, however, that for this to work, both A
and b
need to not be null
. Otherwise, PHP will throw an error (I think).
这篇关于PHP SimpleXML检查孩子是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文