• array_multisort 二维数组排序


    * 用PHP自带array_multisort函数排序 


    ```

                $data = [
                    ['volume' => 67, 'edition' => 2],
                    ['volume' => 86, 'edition' => 1],
                    ['volume' => 85, 'edition' => 6],
                    ['volume' => 98, 'edition' => 2],
                    ['volume' => 86, 'edition' => 6],
                    ['volume' => 67, 'edition' => 7],
                ];
            
                foreach ($data as $key => $row)
                {
                    $volume[$key] = $row['volume'];
                    $edition[$key] = $row['edition'];
                }
            
                array_multisort($volume,SORT_DESC,$edition,SORT_ASC,$data);
                // SORT_DESC 不可加"";
                dump($data);
                exit;
     

    ```

    ```

    输出结果:

    复制代码 代码如下:
    Array
    (
        [0] => Array
            (
                [volume] => 98
                [edition] => 2
            )
        [1] => Array
            (
                [volume] => 86
                [edition] => 1
            )
        [2] => Array
            (
                [volume] => 86
                [edition] => 6
            )
        [3] => Array
            (
                [volume] => 85
                [edition] => 6
            )
        [4] => Array
            (
                [volume] => 67
                [edition] => 2
            )
        [5] => Array
            (
                [volume] => 67
                [edition] => 7
            )
    )

    ```

  • 相关阅读:
    vue 路由跳转传参
    vue better-scroll 下拉上拉,加载刷新
    H5点击拨打电话,发短信
    vue搭建项目
    How to determine the socket connection up time on Linux
    @ContextConfiguration注解
    MySQL修改主键属性
    软件测试工程师面试(一)
    Python实现不同格式打印九九乘法表
    MySQL 5.1安装和配置过程中遇到的问题
  • 原文地址:https://www.cnblogs.com/pansidong/p/9822543.html
Copyright © 2020-2023  润新知