【发布时间】:2012-02-03 04:08:36
【问题描述】:
在下面的 SimpleXMLElement Object $results 中,我想从 TEST 数组中删除 ID 为 13011146 的元素。我不确定如何正确访问值为1 的数组键,所以我使用了计数器$i,但这给了我一个错误Node no longer exists,指向foreach 行。
TL;DR:你如何取消$result->TEST[1] 的设置?
SimpleXMLElement Object
(
[TEST] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ID] => 13011145
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ID] => 13011146
)
)
)
)
PHP:
$i = 0;
foreach($results->TEST as $key => $value) {
if( (string)$value['ID'] == 13011146 ) {
unset($results->TEST[$i]);
}
$i++;
}
【问题讨论】:
-
您能否提供
XML为主要SimpleXMLElement Object