We are fetching data from a remote server via their API. Unfortunately, their API does not order the returned data by date.
I am trying, without much success, to figure out how to re-organize the data so that it is ordered by the next_bookable_date. We are using PHP and SimpleXMLElement to parse the data and create a string which is then inserted into a webpage. But the current result is in the same order as data appears in the returned XML.
The basic XML results are below. There is much more data, that I stripped out to save space.
SimpleXMLElement Object
(
[request] => GET search.xml?start_date=2013-05-03&end_date=2013-05-17
[error] => OK
[total_tour_count] => 4
[tour] => Array
(
[0] => SimpleXMLElement Object
(
[next_bookable_date] => 2013-05-13
[tour_name] => Thailand Tour
)
[1] => SimpleXMLElement Object
(
[next_bookable_date] => 2013-05-12
[tour_name] => Bali Tour
)
[2] => SimpleXMLElement Object
(
[next_bookable_date] => 2013-05-05
[tour_name] => Hawaii Tour
)
[3] => SimpleXMLElement Object
(
[next_bookable_date] => 2013-05-06
[tour_name] => Bhutan Tour
)
)
)
The PHP code we are using to generate the html string (again stripped of a bit of html code to save space):
foreach($result->tour as $tour) {
$tourname = $tour->tour_name;
$tourdate = $tour->next_bookable_date;
// create string for dpt-soon
$dpt_soon_list .= "<li> some html using the above values </li>\n";
}
Is there a way to re-order the XML data once we receive it from the remote server? Or is there a way to reorder the PHP output when running the foreach?