使用Laravel

时间:2019-02-12 18:10:21

标签: php arrays laravel collections

我有一个集合,可以为每个玩家获取积分。

        $rankings = Player::with(['rankings'])
              ->map(function($item){
                   return ['points' => $item->rankings->pluck('points')];
               })->sortByDesc('total');

这给了我以下信息:

            [
                {
                    "player": 5,
                    "points": [
                        4,
                        2,
                        1,
                        2,
                        2,
                        3
                    ]
                },
                {
                    "player": 1,
                    "points": [
                        2,
                        3,
                        3,
                        4,
                        4,
                        4
                    ]
                },
                {
                    "player": 10,
                    "points": [
                        1,
                        4,
                        2,
                        1,
                        1,
                        2
                    ]
                },
                {
                    "player": 6,
                    "points": [
                        3,
                        1,
                        1,
                        3,
                        3,
                        1
                    ]
                }
        ]

我该如何对收藏进行排序,以使得分最高的球员获得1分?那些得分最高的2分仍然排名第二,依此类推?而如果有玩家获得第1点的并列,那么得到那些拥有更多第2点的玩家?

            [
                {
                    "player": 10,
                    "points": [
                        1,
                        4,
                        2,
                        1,
                        1,
                        2
                    ]
                },
                {
                    "player": 6,
                    "points": [
                        3,
                        1,
                        1,
                        3,
                        3,
                        1
                    ]
                },
                {
                    "player": 5,
                    "points": [
                        4,
                        2,
                        1,
                        2,
                        2,
                        3
                    ]
                },
                {
                    "player": 1,
                    "points": [
                        2,
                        3,
                        3,
                        4,
                        4,
                        4
                    ]
                },
        ]

谢谢。

0 个答案:

没有答案