zoukankan      html  css  js  c++  java
  • 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
            )
    )

    ```

  • 相关阅读:
    openstack项目【day23】:glance基础
    openstack项目【day23】:openstack组件介绍
    openstack项目【day23】:云计算介绍(一)
    学习有五个层次和境界
    gdb 初步学习记录
    Linux samba 服务的配置
    QT 5.7.0 移植之 tslib 编译配置
    tiny4412 u-boot 启动参数的设置
    Windows 只能安装32位虚拟机问题
    Tiny4412 虚拟机交叉编译环境的设置以及编译u-boot 和 kernel
  • 原文地址:https://www.cnblogs.com/pansidong/p/9822543.html
Copyright © 2011-2022 走看看