I have several identical elements with different attributes that I\'m accessing with SimpleXML:
If you want to cut list of similar (not unique) child elements, for example items of RSS feed, you could use this code:
for ( $i = 9999; $i > 10; $i--) {
unset($xml->xpath('/rss/channel/item['. $i .']')[0]->{0});
}
It will cut tail of RSS to 10 elements. I tried to remove with
for ( $i = 10; $i < 9999; $i ++ ) {
unset($xml->xpath('/rss/channel/item[' . $i . ']')[0]->{0});
}
But it works somehow randomly and cuts only some of the elements.