可能重複:
How to sort arrays inside an array?
Sort an array by a child array's value in PHPPHP:由子值排序陣列
我有一個數組,看起來像這樣:
[0] => Array {
[ID] => 1651,
[DESCR] => "blabla",
[SORTNR] => 1,
},
[1] => Array {
[ID] => 456,
[DESCR] => "bleble",
[SORTNR] => 3,
},
[2] => Array {
[ID] => 158,
[DESCR] => "bliblablub",
[SORTNR] => 2,
},
現在我想要使用值對子排列進行排序降序,所以在這裏它應該看起來像這樣:
[1] => Array {
[ID] => 456,
[DESCR] => "bleble",
[SORTNR] => 3,
},
[2] => Array {
[ID] => 158,
[DESCR] => "bliblablub",
[SORTNR] => 2,
},
[0] => Array {
[ID] => 1651,
[DESCR] => "blabla",
[SORTNR] => 1,
},
我該如何在PHP中正確執行該操作?我現在嘗試了一些東西四個小時,我找不到任何好的解決方案....
Thx求助!改編自PHP uasort()
manual page
爲簡潔起見,您可以在cmp()函數中執行'返回$ a ['SORTNR'] - $ b ['SORTNR']'' – Vikk