array_multisort函数使用,赞

需求 数组排序   id降序,value降序,nii升序

       $arr = array(
            1=>array(
                'id' => 5,
                'value' => '2018-12-20 12:09:30',
                'nii' => '6',
            ),
            2=>array(
                'id' => 5,
                'value' => '2018-12-20 12:09:30',
                'nii' => '2',
            ),
            3=>array(
                'id' => 5,
                'value' => '2018-12-21 12:09:30',
                'nii' => '5',
            ),
            4=>array(
                'id' => 8,
                'value' => '2018-12-21 12:09:30',
                'nii' => '5',
            ),
            5=>array(
                'id' => 6,
                'value' => '2018-12-22 12:09:30',
                'nii' => '5',
            )
        );
        print_r($arr);
    $id     = array_column($arr,'id');
    $value  = array_column($arr,'value');
    $nii    = array_column($arr,'nii');
//print_r([$id,$value,$nii]);exit;
        array_multisort($id,SORT_DESC,$value,SORT_DESC,$nii,SORT_ASC,$arr);
        print_r($arr);        exit;

打印情况,解决!

Array
(
    [1] => Array
        (
            [id] => 5
            [value] => 2018-12-20 12:09:30
            [nii] => 6
        )

    [2] => Array
        (
            [id] => 5
            [value] => 2018-12-20 12:09:30
            [nii] => 2
        )

    [3] => Array
        (
            [id] => 5
            [value] => 2018-12-21 12:09:30
            [nii] => 5
        )

    [4] => Array
        (
            [id] => 8
            [value] => 2018-12-21 12:09:30
            [nii] => 5
        )

    [5] => Array
        (
            [id] => 6
            [value] => 2018-12-22 12:09:30
            [nii] => 5
        )

)
Array
(
    [0] => Array
        (
            [id] => 8
            [value] => 2018-12-21 12:09:30
            [nii] => 5
        )

    [1] => Array
        (
            [id] => 6
            [value] => 2018-12-22 12:09:30
            [nii] => 5
        )

    [2] => Array
        (
            [id] => 5
            [value] => 2018-12-21 12:09:30
            [nii] => 5
        )

    [3] => Array
        (
            [id] => 5
            [value] => 2018-12-20 12:09:30
            [nii] => 2
        )

    [4] => Array
        (
            [id] => 5
            [value] => 2018-12-20 12:09:30
            [nii] => 6
        )

)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值