php SimpleXML check if a child exists

后端 未结 16 2199
粉色の甜心
粉色の甜心 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:58

    If you have PHP 5.3, you can just use $a->count(). Otherwise, scippie's solution using @count($a->children()) works well. I find I don't need the @ but older PHP implementations may need it.

提交回复
热议问题