• 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
            )
    )

    ```

  • 相关阅读:
    Flask(7)- request 对象
    2021暑假训练赛1 基于Codeforce#479(div3)
    AtCoder ARC 115 E
    C++11 noexcept 关键字用法学习
    AtCoder ABC 049 C
    【算法学习笔记】块状数据结构:分块思想
    「Codeforces 1131D」Gourmet Choice
    AtCoder Beginner Contest 172 (C题前缀和 + 二分,D题筛因子,E题容斥定理)
    第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(沈阳)补题记录
    泛型动态数组
  • 原文地址:https://www.cnblogs.com/pansidong/p/9822543.html
Copyright © 2020-2023  润新知