我需要像这样对数组进行排序
[0] => Array
(
[id] => 5
[stats] => Array
(
[SessionsPlayed] => 1
)
)
[1] => Array
(
[id] => 88
[stats] => Array
(
[SessionsPlayed] => 6
)
)
[2] => Array
(
[id] => 22
[stats] => Array
(
[SessionsPlayed] => 9
)
)
按sessionplays列降序排列,就像这样
[2] => Array
(
[id] => 22
[stats] => Array
(
[SessionsPlayed] => 9
)
)
[1] => Array
(
[id] => 88
[stats] => Array
(
[SessionsPlayed] => 6
)
)
[0] => Array
(
[id] => 5
[stats] => Array
(
[SessionsPlayed] => 1
)
)
我试图在线查看如何解决这个问题,但我找到的所有答案只能排序一个孩子(例如id列)以下是我看过的帖子。https://stackoverflow.com/a/16788610/1319033https://stackoverflow.com/a/2699110/1319033
使用PHP的ussort
usort($array, function($a, $b) {
return $b['stats']['SessionsPlayed'] - $a['stats']['SessionsPlayed'];
// $b - $a for descending order
});