In the following SimpleXMLElement Object $results, I would like to remove the element with ID 13011146 from the TEST array. I'm not sure how to properly access the array key with value 1, so I'm using a counter $i, but that gives me an error Node no longer exists, pointing to the foreach line.
TL;DR: How do you unset $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++;
}
XMLfor mainSimpleXMLElement Object