PHP count()函数讲解
来源:懂视网
责编:小采
时间:2020-11-27 14:43:33
PHP count()函数讲解
PHP count()函数讲解:PHP count() 函数 实例 计算 car 节点的子节点个数: <?php $xml=<<<XML <cars> <car name=Volvo> <child/> <child/> <child/> <child/> <
导读PHP count()函数讲解:PHP count() 函数 实例 计算 car 节点的子节点个数: <?php $xml=<<<XML <cars> <car name=Volvo> <child/> <child/> <child/> <child/> <
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()
函数计算指定节点的子节点个数。
语法

总结
PHP count()函数讲解
PHP count()函数讲解:PHP count() 函数 实例 计算 car 节点的子节点个数: <?php $xml=<<<XML <cars> <car name=Volvo> <child/> <child/> <child/> <child/> <