哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

SimpleXMLIterator::hasChildren

(PHP 5, PHP 7, PHP 8)

SimpleXMLIterator::hasChildrenChecks whether the current element has sub elements

说明

public SimpleXMLIterator::hasChildren(): bool

This method checks whether the current SimpleXMLIterator element has sub-elements.

参数

此函数没有参数。

返回值

true if the current element has sub-elements, otherwise false

范例

示例 #1 Check whether the current element has sub-elements

<?php
$xml 
= <<<XML
<books>
    <book>
        <title>PHP Basics</title>
        <author>Jim Smith</author>
    </book>
    <book>XML basics</book>
</books>
XML;

$xmlIterator = new SimpleXMLIterator$xml );
for( 
$xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
    if(
$xmlIterator->hasChildren()) {
        
var_dump($xmlIterator->current());
    }
}
?>

以上例程会输出:

object(SimpleXMLIterator)#2 (2) {
  ["title"]=>
  string(10) "PHP Basics"
  ["author"]=>
  string(9) "Jim Smith"
}
打开 哈希空间 微信小程序中查看更佳