PHP多维数组排序问题

多维数组排序,如果a相等,那么比较bb相等再比较c,排序完在生成个新字段sort 作为标识

$arr = [

    1 =>   [

        'a' => 1,

        'b' => 2,

        'c' => 4,

    ], 

    0 =>   [

        'a' => 1,

        'b' => 2,

        'c' => 3,

    ], 

    5 =>   [

        'a' => 3,

        'b' => 2,

        'c' => 3,

    ], 

    2 =>   [

        'a' => 2,

        'b' => 2,

        'c' => 3,

    ], 

    4 =>   [

        'a' => 4,

        'b' => 2,

        'c' => 3,

    ], 

];


郎朗坤
浏览 509回答 1
1回答

繁星点点滴滴

好吧 ,我是这样用的<?php$a = $b = $c = [];array_map(function( $value ) use ( &$a,&$b,&$c ){&nbsp; &nbsp; &nbsp; array_push($a, $value['a']);&nbsp; &nbsp; &nbsp; array_push($b, $value['b']);&nbsp; &nbsp; &nbsp; array_push($c, $value['c']);} , $arr);$count = $arr;var_dump($count);array_multisort(&nbsp; &nbsp; $a,SORT_ASC,&nbsp; &nbsp; $b,SORT_ASC,&nbsp; &nbsp; $c,SORT_ASC,&nbsp; &nbsp; $arr);var_dump($arr);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript