我有一个 simpleXml 对象,想从该对象中读取数据,我是 PHP 新手,不太了解如何执行此操作。 object 详情如下。
我需要阅读 [描述] 和 [营业时间]。谢谢。
SimpleXMLElement Object (
[@attributes] => Array (
[type] => array
)
[time-entry] => Array (
[0] => SimpleXMLElement Object (
[date] => 2010-01-26
[description] => TCDM1 data management: sort & upload
[hours] => 1.0
[id] => 21753865
[person-id] => 350501
[project-id] => 4287373
[todo-item-id] => SimpleXMLElement Object (
[@attributes] => Array (
[type] => integer
[nil] => true
)
)
)
[1] => SimpleXMLElement Object (
[date] => 2010-01-27
[description] => PDCH1: HTML
[hours] => 0.25
[id] => 21782012
[person-id] => 1828493
[project-id] => 4249185
[todo-item-id] => SimpleXMLElement Object (
[@attributes] => Array (
[type] => integer
[nil] => true
)
)
) ) )
请帮帮我。我尝试了很多东西,但语法不正确。
最佳答案
上面的内容真的很难看,如果能给个截图或者给个行距和缩进就更好了 如果你有一个对象
$xml是一个simplexml对象,你可以像这样访问元素
$xml->element.
看起来是一个时间条目的元素,在这种情况下你会像这样循环:
foreach( $xml->{'time-entry'} as $time_entry ) {
echo $time_entry->description . "<br />\n";
}
关于php - 我如何在 PHP 中循环遍历 SimpleXML 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2900455/