我有这个阵列
Array ( [0] => Array ( [brand] => blah blah [location] => blah blah [address] => blah blah [city] => blah blah [state] => CA [zip] => 90210 [country] => USA [phone] => 555-1212 [long] => -111 [lat] => 34 [distance] => 3.08 ) [1] => Array ( [brand] => blah blah [location] => blah blah [address] => blah blah [city] => blah blah [state] => CA [zip] => 90210 [country] => USA [phone] => 555-1212 [long] => -111 [lat] => 34 [distance] => 5 ) . . . }
我希望能够按距离对哈希中的数组进行排序.救命!非常感谢
您需要先提取所有距离,然后将距离和数据传递给函数.如
array_multisort文档中的示例3所示.
foreach ($data as $key => $row) { $distance[$key] = $row['distance']; } array_multisort($distance,SORT_ASC,$data);
这假设您首先需要最短距离,否则将SORT_ASC更改为SORT_DESC