微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 无法弄清楚如何确定SimpleXML节点是否为空

所以我有这个代码

foreach ($xml->PrintQuestion as $PrintQuestion) {

     //if hint doesn't exist, store question id
     if (!$PrintQuestion->content->multichoice->Feedback->hint->Passage) {

         fwrite($fp, "<contentid filename=\"$value\">" . $PrintQuestion->attributes()->id . "</contentid>");

     }

}

基本上,如果Passage节点存在,我正在尝试将ID保存到XML文件,但它似乎存储了每个ID,无论节点是否存在于Passage中.

解决方法:

如果你使用empty()会发生什么

if( empty($PrintQuestion->content->multichoice->Feedback->hint->Passage) ) {

    fwrite($fp, "<contentid filename=\"$value\">" . $PrintQuestion->attributes()->id . "</contentid>");      

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐