Sorting array by count of subarray

前端 未结 3 1933
情歌与酒
情歌与酒 2021-01-14 01:06

I have an array looking like this:

Array(
   [\'some_first_category\'] => Array(
            [\'some_first_name\'] => Array(
                                   


        
3条回答
  •  终归单人心
    2021-01-14 01:47

    Using uksort:

    uksort($yourArray, function($a, $b) { return count($b) - count($a); });
    

    Using array_multisort:

    array_multisort(array_map('count', $yourArray), SORT_DESC, $yourArray);
    

    and you can see uasort as well

    best of luck :)

提交回复
热议问题