I’m using SimpleXML to parse a rss feed and if an attribute in returned arrays by SimpleXML matches with my string show data. but some items are duplicated in XML file and I want to use just their first occurrence. but I’m getting all the duplicated results.
foreach($feed->city as $city){
if(in_array($city['Name'], $cities)){
echo $city['Name'].'<br />';
}
}
where $feed->city is my XML data and $cities is my array.
I would use php’s Xpath library to do this. Xpath 2.0 could do this directly, but the built in Xpath 1.0 language still gets you very close.
from here you have a DOMNodeList class. throw it in an array and remove duplicates. I don’t ahve a php environment around right now to finish it up, but I wanted to offer a different direction than just simplXML by itself.