我想這個數組排序:排序價值的陣列,而不是關鍵
Array ([0] => Array ([qid] => 1_2_qb0 [hendel] => 7.7) [1] => Array ([qid] => 1_2_qb1 [hendel] => 4.13) [2] => Array ([qid] => 1_2_qb2 [hendel] => 6.61) [3] => Array ([qid] => 1_2_qb3 [hendel] => 7.22) [4] => Array ([qid] => 1_2_qb4 [hendel] => 3.13) [5] => Array ([qid] => 1_2_qb5 [hendel] => 6.91) [6] => Array ([qid] => 1_2_qb6 [hendel] => 7.3) [7] => Array ([qid] => 1_2_qb7 [hendel] => 6.65) [8] => Array ([qid] => 1_2_qb8 [hendel] => 6.7) [9] => Array ([qid] => 1_3_qb0 [hendel] => 7.43) [10] => Array ([qid] => 1_3_qb1 [hendel] => 7.7) [11] => Array ([qid] => 1_3_qb2 [hendel] => 7.39) [12] => Array ([qid] => 1_3_qb3 [hendel] => 7.83) [13] => Array ([qid] => 1_3_qb4 [hendel] => 7.26) [14] => Array ([qid] => 1_3_qb5 [hendel] => 7.04) [15] => Array ([qid] => 1_3_qb6 [hendel] => 7.65) [16] => Array ([qid] => 1_3_qb7 [hendel] => 7.43) [17] => Array ([qid] => 1_4_qb0 [hendel] => 7.22) [18] => Array ([qid] => 1_4_qb1 [hendel] => 7.26) [19] => Array ([qid] => 1_4_qb2 [hendel] => 7.43) [20] => Array ([qid] => 1_4_qb3 [hendel] => 8.09))
從高分到低分的「亨德爾」,但「QID」必須涉及到了「亨德爾」值。 排序數組不起作用。 (ASORT,arsort,ksort,krsort =>國旗:sort_nummeric)
印刷值而不排序:
1_2_qb0 : 7.7
1_2_qb1 : 4.13
1_2_qb2 : 6.61
1_2_qb3 : 7.22
1_2_qb4 : 3.13
1_2_qb5 : 6.91
1_2_qb6 : 7.3
1_2_qb7 : 6.65
1_2_qb8 : 6.7
1_3_qb0 : 7.43
1_3_qb1 : 7.7
1_3_qb2 : 7.39
1_3_qb3 : 7.83
1_3_qb4 : 7.26
1_3_qb5 : 7.04
1_3_qb6 : 7.65
1_3_qb7 : 7.43
1_4_qb0 : 7.22
1_4_qb1 : 7.26
1_4_qb2 : 7.43
1_4_qb3 : 8.09
與分選(krsort):
1_4_qb3 : 8.09
1_4_qb2 : 7.43
1_4_qb1 : 7.26
1_4_qb0 : 7.22
1_3_qb7 : 7.43
1_3_qb6 : 7.65
1_3_qb5 : 7.04
1_3_qb4 : 7.26
1_3_qb3 : 7.83
1_3_qb2 : 7.39
1_3_qb1 : 7.7
1_3_qb0 : 7.43
1_2_qb8 : 6.7
1_2_qb7 : 6.65
1_2_qb6 : 7.3
1_2_qb5 : 6.91
1_2_qb4 : 3.13
1_2_qb3 : 7.22
1_2_qb2 : 6.61
1_2_qb1 : 4.13
1_2_qb0 : 7.7
它的代碼一塌糊塗,但我認爲老朋友'usort'會做的東西 –
'usort($ myArray的,函數($ A,$ B) {if($ a ['hendel'] == $ b ['hendel']){ return 0; } return($ a ['hendel'] <$ b ['hendel'])?-1: 1;});' –
@MarkBaker我認爲,那就是'return $ a ['hendel'] <$ b ['hendel']? - 1:$ a ['hendel']!= $ b ['hendel' ]':p –