PHPcount()函数实例计算car节点的子节点个数:<?php$xml=<<<XML<cars><carname="Volvo
PHP count() 函数
实例
计算 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());
}
?>
定义和用法
count()
函数计算指定节点的子节点个数。
语法
count();
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接
count()函数 php count()函数 count()函数讲解