可能重複:
Sorting an associative array in PHP
Sorting a multidimensional array in PHP?PHP陣列中順序排序
我有一個系統,它允許訂單被分配到輸送driver.The以下源帶來了一個當前可用分銷商名單以及他們遠離客戶的距離:
$franchise_a_status = array();
$franchise_a_status[] = array('id' => '', 'text' => 'Please Select');
$franchise_query = mysql_query("select franchise_id, franchise_surname, franchise_firstname, franchise_postcode, franchise_availability from " . TABLE_FRANCHISE . " where franchise_availability=1");
$origin = $cInfo->entry_postcode;
while ($franchise = mysql_fetch_array($franchise_query)) {
$destination = $franchise['franchise_postcode'];
$json = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&mode=driving&sensor=false&units=imperial");
$result = json_decode($json, true);
$distance = $result['rows'][0]['elements'][0]['distance']['text'];
$franchise_a_status[] = array('id' => $franchise['franchise_id'],
'text' => $franchise['franchise_surname']. ' ' .$franchise['franchise_firstname'].' '.'('.$distance.')');
}
列表使用下拉菜單中顯示:
array('text' => tep_draw_pull_down_menu('franchise_id',$franchise_a_status));
我需要的數組中最高的距離最短距離的順序進行排序。
如何使用MySQL對它們進行排序呢? – Havelock 2012-07-06 10:07:37
用'usort'研究一下。 [usort'的PHP文檔](http://au.php.net/manual/en/function.usort.php) – 2012-07-06 10:08:36