二维数组排序

public function index()
    {
        $data = [
            [
                'id' => 1,
                'b'  => '11',
                'c'  => '11',
            ],
            [
                'id' => 2,
                'a'  => '33',
                'b'  => '33',
            ],
            [
                'id' => 3,
                'a'  => '22',
                'b'  => '22',
            ]
        ];

        //根据字段a对数组$data进行降序排列
        $a_arr = array_column($data, 'a');
        array_multisort($a_arr, SORT_DESC, $data);
        return $data;
    }

 

posted @ 2021-09-08 09:10  CanyingV  阅读(34)  评论(0编辑  收藏  举报