PHP count()Functions

PHP SimpleXML 参考手册PHP SimpleXML Reference Manual

Examples

Count the number of child nodes of the car node:

<?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 Example »

Definition and Usage

The count() function counts the number of child nodes of a specified node.


Syntax

count();

Technical Details

Return value: Returns the number of child nodes of an element.
PHP Version: 5.3+


PHP SimpleXML 参考手册PHP SimpleXML Reference Manual Other Extensions