count
Calculate the number of units in an array, or the number of attributes in an object
The count()
function is used to calculate the number of child nodes of a specified node.
Calculate the number of child nodes of the <car> element:
<?php $xml = <<< XML <cars> <car name="Volvo"> <child/> <child/> <child/> <child/> </car> <car name="BMW"> <child/> <child/> </car> </cars> XML ; $elem = new SimpleXMLElement ( $xml ) ; foreach ( $elem as $car ) { printf ( "%s has %d children.<br>" , $car [ 'name' ] , $car -> count ( ) ) ; } ?>
Run the instance
SimpleXMLElement :: count ( ) ;