APIを介してリモートサーバーからデータを取得しています。残念ながら、彼らの API は返されたデータを日付順に並べ替えません。
next_bookable_date で順序付けられるようにデータを再編成する方法を見つけようとしていますが、あまり成功していません。PHP と SimpleXMLElement を使用してデータを解析し、Web ページに挿入される文字列を作成します。ただし、現在の結果は、返された XML に表示されるデータと同じ順序になっています。
基本的な XML の結果は次のとおりです。スペースを節約するために取り除いたデータがはるかに多くあります。
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
)
)
)
HTML 文字列を生成するために使用している PHP コード (ここでも、スペースを節約するために HTML コードを少し取り除いています):
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";
}
リモート サーバーから受け取った XML データの順序を変更する方法はありますか? または、foreach の実行時に PHP 出力を並べ替える方法はありますか?