简单教程
提交运行
代码编辑器:
<?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()); }
运行结果: