zoukankan      html  css  js  c++  java
  • 多维数组排序

    https://blog.csdn.net/zhezhebie/article/details/79446817

     $exampleArray1 = $exampleArray2 = array(
         0 => 'example1',
         1 => 'Example10',
         2 => 'example12',
         3 => 'Example2',
         4 => 'example3',
         5 => 'EXAMPLE10',
         6 => 'example10'
     );

    default sorting

    asort($exampleArray1);
    result:
       Array
       (
       [5] => EXAMPLE10
       [1] => Example10
       [3] => Example2
       [0] => example1
       [6] => example10
       [2] => example12
       [4] => example3
       )

    alphanumeric with case-sensitive data sorting by values

    asort($exampleArray2, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL);
    
     result:
       Array
     (
         [0] => example1
         [3] => Example2
         [4] => example3
         [5] => EXAMPLE10
         [1] => Example10
         [6] => example10
         [2] => example12
     )
    https://blog.csdn.net/zhezhebie/article/details/72158753  多维数组进行排序

    <?php
    
    $data = [
        [
            'id' => 13,
            'name' => 'Arthur Dent',
        ],
        [
            'id' => 22,
            'name' => 'Ford Prefect',
        ],
        [
            'id' => 5,
            'name' => 'Trillian Astra',
        ],
    ];
    
    //对多维数组进行排序,就是这么简单!
    // array_multisort(array_column($data, 'id'), SORT_ASC, $data);
    
    array_multisort(array_column($data, 'id'), SORT_DESC, $data);
    echo "<pre>";
    print_r($data);
    echo "</pre>";


    
    












  • 相关阅读:
    java中的工厂模式(简单工厂模式+工厂方法模式)
    代码集合
    java读取文件的路径问题
    使用ZXing库生成二维码
    java设计模式-装饰者模式
    android文件流缓存
    java8 新特性
    Excel导出
    常用的在线工具
    Java加密简介
  • 原文地址:https://www.cnblogs.com/hehexu/p/8915963.html
Copyright © 2011-2022 走看看