This question already has an answer here:
I have an XML array with a list of page titles. I extracted the date part from the title and got an array going like:
Array ( [0] => 2012 )
Array ( [0] => 2013 )
Array ( [0] => 2013 )
Array ( [0] => 2014 )
Array ( [0] => 2014 )
Array ( [0] => 2014 )
Array ( [0] => 2015 )
My question is how can I loop through the date array so that I get an empty line between every new year, like:
2012 - BLA
2013 - BLA BLA
2013 - BLABLA
2014- BLA BLA BLA
2014- BLA BLA BLA
2014- BLA BLA BLA
2015- BLA
What I thought is extracting the date part from the title and then going through the array and isnert a new line for every new unique value. Looking around I couldn't find a way of doing that without removing the duplicate values. Is there a way to do it? Please, I'd appreciate any help.
Regards
XML sample:
SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => Results [description] => Search Results [link] => http://...... [item] => Array ( [0] => SimpleXMLElement Object ( [title] => 2012 Blah , Blah Blah, Blah [description] => <b>Introduction</b> ...Long text.. [link] => http... [1] => SimpleXMLElement Object ( [title]
...
What I've done is took the $year part out with :
$year = substr(str_replace($type.", ", "", $xmlfeed->channel->item[$i]->title),0,4);
</div>