SimpleXML SimpleXMLIterator::hasChildren

(PHP 5, PHP 7, PHP 8)

SimpleXMLIterator::hasChildren — 현재 요소에 하위 요소가 있는지 확인


설명

public SimpleXMLIterator::hasChildren(): bool

이 메서드는 현재 SimpleXMLIterator 요소에 하위 요소가 있는지 여부를 확인합니다.


매개변수

이 함수에는 매개변수가 없습니다.


반환 값

현재 요소에 하위 요소가 있으면 true, 그렇지 않으면 false


Examples

예제 #1 현재 요소에 하위 요소가 있는지 확인

                  
<?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"
}