我有以下格式的數組:Array( [123451000] => Array ( [total] => 70 [total_tech] => 36 [duration] => 300 ) [123451001] => Array ( [total] => 9 [total_tech] => 3 [duration] => 197 ) [123451002] => Array ( [total] => 103 [total_tech] => 97 [duration] => 273 ))我正在遍歷它,但想知道是否可以按total?編輯:我當前的 foreach 循環foreach($agents as $agent => $option) { //$talktime = secondsToTime($x["talktime_sum"]); $display.= '<tr> <td>'.get_dtypes('phone', $agent).'</td> <td>'.number_format($option["total_calls"]).'</td> <td>'.number_format($option["technical_calls"]).'</td> <td>'.number_format($option["sales_calls"]).'</td> <td>'.number_format($option["other_calls"]).'</td> <td>'.$option["total_duration"].'</td> </tr>';}
1 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
uasort($array, function ($a, $b) {
return $a['total'] <=> $b['total'];
});
usort 是一個使用快速排序對數組進行排序的函數,使用用戶給定的函數進行比較。
~~uksort是它的一個變體,它保留了數組的鍵~~
<=>是“宇宙飛船”運算符,-1如果左側較大,1右側較大,并且0它們相等,則返回。
編輯 的uksort排序使用的關鍵,而不是保持關鍵。 uasort是對值進行排序并保留數組鍵的那個
- 1 回答
- 0 關注
- 244 瀏覽
添加回答
舉報
0/150
提交
取消