App下载

demo_func_simplexml_count 在线工具

demo_func_simplexml_count 在线工具

<?php
$xml=<<<XML
<cars>
&nbsp;&nbsp;  <car name="Volvo">
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;  </car>
&nbsp;&nbsp;  <car name="BMW">
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;&nbsp;&nbsp;    <child/>
&nbsp;&nbsp;  </car>
</cars>
XML;

$elem = new SimpleXMLElement($xml);
foreach ($elem as $car)
&nbsp;&nbsp;  {
&nbsp;&nbsp;  printf("%s has %d children.<br>", $car['name'], $car->count());
&nbsp; }
?>
运行结果