我有以下陣列從多維數組前5名的值:獲取PHP
Array (
[0] => Array (
[count] => 9
[user_id] => 2
)
[1] => Array (
[count] => 25
[user_id] => 1
)
[2] => Array (
[count] => 20
[user_id] => 3)
[3] => Array (
[count] => 6
[user_id] => 56)
[4] => Array (
[count] => 2
[user_id] => 37)
[5] => Array (
[count] => 1
[user_id] => 0
))
這僅僅是一個樣品。實際的數組將包含更多的子數組。
我需要能夠從「count」中獲得前五個值並將它們與相關的「user_id」一起存儲。
最後的結果需要是這個樣子:
Array (
[0] => Array (
[count] => 25
[user_id] => 1
)
[1] => Array (
[count] => 20
[user_id] => 3
)
[2] => Array (
[count] => 9
[user_id] => 2
)
[3] => Array (
[count] => 6
[user_id] => 56
)
[4] => Array (
[count] => 2
[user_id] => 37
)
[5] => Array (
[count] => 1
[user_id] => 0
))
如果可以做到這一點,只需重新排序的陣列,這是罰款。
謝謝!
它的多維並不十分改變問題的事實。您仍然可以使用快速選擇,並對最後五個元素使用select排序。 – bdares
[如何在PHP中對數組進行排序?](http://stackoverflow.com/questions/2978447/how-to-sort-an-array-of-arrays-in-php) – Gordon
可能的重複[php usort或array multisort](http://stackoverflow.com/questions/3013974/php-usort-or-array-multisort) – Gordon