php SimpleXML check if a child exists

后端 未结 16 2195
粉色の甜心
粉色の甜心 2020-11-27 06:24

A->b->c might exist but c might not exist. How do I check it?

16条回答
  •  失恋的感觉
    2020-11-27 06:48

    if($A->b->c != null) //c exists
    

    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).

提交回复
热议问题