downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SimpleXMLIterator::key> <SimpleXMLIterator::getChildren
Last updated: Fri, 20 Nov 2009

view this page in

SimpleXMLIterator::hasChildren

(PHP 5 >= 5.1.0)

SimpleXMLIterator::hasChildrenChecks whether the current element has sub elements.

Description

bool SimpleXMLIterator::hasChildren ( void )

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

Parameters

This function has no parameters.

Return Values

TRUE if the current element has sub-elements, otherwise FALSE

Examples

Example #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());
    }
}
?>

The above example will output:

object(SimpleXMLIterator)#2 (2) {
  ["title"]=>
  string(10) "PHP Basics"
  ["author"]=>
  string(9) "Jim Smith"
}



add a note add a note User Contributed Notes
SimpleXMLIterator::hasChildren
There are no user contributed notes for this page.

SimpleXMLIterator::key> <SimpleXMLIterator::getChildren
Last updated: Fri, 20 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites