-4

重複の可能性:
PHP で連想配列を
ソートする PHP で多次元配列をソートしますか?

注文を配送ドライバーに割り当てることができるシステムを持っています。次のソースは、現在利用可能なディストリビューターのリストと、それらが顧客から離れている距離を示しています。

$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));   

最短距離から最長距離の順に配列をソートする必要があります。

4

1 に答える 1

0
  1. に距離を追加し$franchise_a_statusます。
  2. 距離に従ってソートします ( usort )。
  3. 距離値なしで新しい配列を作成します ( array_mapまたはforeach )。
于 2012-07-06T10:11:40.863 に答える