sort array values by key using php

前端 未结 2 1339
灰色年华
灰色年华 2020-12-07 03:59

i have an PHP array in the following format,

Array
(
    [0] => Array
        (
            [40] => 2
            [80] => 1
            [20] =>          


        
相关标签:
2条回答
  • 2020-12-07 04:33

    use ksort , which sorts an array by key

    Assuming your array is $array

    foreach($array as $a){
       foreach($a as $sort_me){
         ksort($sort_me);
       }
    }
    
    0 讨论(0)
  • 2020-12-07 04:36

    Use array_combine (http://php.net/manual/en/function.array-combine.php) to combine the arrays and then use ksort (http://php.net/manual/en/function.ksort.php) to sort the keys.

    0 讨论(0)
提交回复
热议问题