I have a multidimensional array (standard RSS fare - channel - item - title) and I'm trying to sort it by title. I'm using SimpleXML and created an array of the items from the SimpleXML objects. Then I made another array of titles from the items array. Then I sorted the items array by title using array_multisort().
It is kind of working. There are 122 items. The sort puts 2 items in order, then 80 items in order, then 38 items in order, then 2 items in order. I'm not sure why it's splitting them up into 4 groups, though.
XML:
<channel>
<item>
<title>Saved To Serve</title>
<guid>http://www.moorelife.org/rss/SavedToServe.xml</guid>
<pubDate>Sun, 06 Nov 2011 11:00:00 CST</pubDate>
</item>
<item>
<title>Filled With All The Fullness Of God</title>
<guid>http://www.moorelife.org/rss/FilledWithAllTheFullnessOfGod.xml</guid>
<pubDate>Mon, 03 Oct 2011 19:00:00 CST</pubDate>
</item>
</channel>
PHP:
<?php
$items = array();
foreach($data->channel->item as $item) {
$items[] = $item;
}
$titles = array();
foreach($items as $item) {
$titles[] = $item["title"];
}
array_multisort($titles, SORT_ASC, $items);
print "<pre>\n";
print_r($items);
print "</pre>\n";
?>
In the xml file, Saved To Serve is right before Filled With All The Fullness Of God (just like the sample). When sorted, FWATFOG should be 50 or so items before STS. In the actual output, STS is #2 and FWATFOG is #86 (in the 3rd alphabetical grouping).
My ultimate goal is to be able to have links for sorting by title or date (preferably with AJAX so we don't have to deal with page reloadings). Do you guys have any ideas or suggestions?
JJ
$pubDates[] = $item["pubDate"];
) and everything outputs in the same order. The only time it outputs differently is if I put a wrong value in and it sorts the way the xml is.