Funkcja PHP count()
Przykład
Policz dzieci elementu <car>:
<?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());
}
?>
Definicja i użycie
Funkcja count() zlicza dzieci określonego węzła.
Składnia
SimpleXMLElement::count();
Szczegóły techniczne
Wartość zwrotu: | Liczba elementów podrzędnych elementu |
---|---|
Wersja PHP: | 5,3+ |
❮ Dokumentacja PHP SimpleXML