我想不通爲什麼asort不工作。其他任何排序都不起作用。 $ hs ['hs_type']是來自MySQL查詢的值。如何按值保存鍵的數組進行排序?
$results = $query->result_array();
$hs_types = array();
foreach($results as $hs) {
$hs_types[$hs['hs_type']]++;
}
$projects = array();
foreach($hs_types as $hs) {
array_push($projects, $hs);
}
asort($projects);
的var_dump我前陣排序:數組(大小= 15)
* 8 => int 1709
* 13 => int 26
* 7 => int 474
* 14 => int 800
* 11 => int 282
* 6 => int 61
* 5 => int 23
* 15 => int 181
* 3 => int 2
* 19 => int 3
* 9 => int 50
* 1 => int 44
* 2 => int 2
* 4 => int 4
* 18 => int 13
的var_dump我陣列後排序:數組(大小= 15)
* 8 => int 2
* 12 => int 2
* 9 => int 3
* 13 => int 4
* 14 => int 13
* 6 => int 23
* 1 => int 26
* 11 => int 44
* 10 => int 50
* 5 => int 61
* 7 => int 181
* 4 => int 282
* 2 => int 474
* 3 => int 800
* 0 => int 1709
我想要的:
* 3 => int 2
* 2 => int 2
* 19 => int 3
* 4 => int 4
* 18 => int 13
* 5 => int 23
* 13 => int 26
* 1 => int 44
* 9 => int 50
* 15 => int 181
* 11 => int 282
* 7 => int 474
* 14 => int 800
* 8 => int 1709
請顯示您的排序代碼。 – deceze