【发布时间】:2014-02-20 20:06:58
【问题描述】:
我有一个如图所示的 XML。我需要遍历每个循环的标签并提取属性attr1。但我不断收到"Illegal string offset"。
我的数据:
<Parent>
<Child>
<ID attr1="123" attr2="567">abc</ID>
<ID attr1="123" attr2="567">abc</ID>
</Child>
</Parent>
我的代码:
foreach ($parentNode->Child->ID as $IDChild => $value)
{
echo $value; // does this output "abc"?
echo $IDChild['attr1']; // need to display "123", but throwing error.
$IDChild['attr1'] = "999"; // also need to update the value in the xml
}
【问题讨论】: