Checks whether the current element has children, if it has; output the current element:
<?php
$bookxml = <<<XML
<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
</book>
</bookstore>
XML;
$xml = new SimpleXMLIterator($bookxml);
for( $xml->rewind(); $xml->valid(); $xml->next() ) {
if($xml->hasChildren()) {
var_dump($xml->current());
echo "<br>";
}
}
?>
Run Example »
The hasChildren() function checks whether the current element has children.
SimpleXMLIterator::hasChildren()
Return Value: | TRUE if the current element has children. FALSE otherwise |
---|---|
PHP Version: | 5.0+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!