Array ( [112566] => Array ( [0] => 1415346186 ) [112370] => Array ( [0] => 1415346220 ) [111064] => Array ( [0] => 1415346259 ) [48629] => Array ( [0] => 1415346287 ) ) 

I have such an array. How to sort it by key value 0, from the largest to the smallest?

I tried this option, but no sorting happens:

 usort($array, function($a, $b){ return ($a[0] - $b[0]); }); 

    2 answers 2

    Read about the array_multisort () function, it will help.

    Update

    Phrase is not finished. I tried what? What is $ mass_us_v_s? Why the first parameter is not an array? http://www.php.su/array_multisort

    With usort function write normally

     function array_sort($a, $b){ if ($a[0] == $b[0]){ return 0; } return ($a[0] < $b[0]) ? -1 : 1; } 
    • Tried: array_multisort ($ mass_us_v_s [(int) $ _ POST ['id']] [0], SORT_DESC, $ mass_us_v_s); - WiNNeR_tig
    • Phrase is not finished. I tried what? What is $ mass_us_v_s? Why the first parameter is not an array? php.su/array_multisort With usort function write normally function array_sort ($ a, $ b) {if ($ a [0] == $ b [0]) {return 0; } return ($ a [0] <$ b [0])? -eleven; } - Get
     foreach ($arr as $key => $row) { $param[$key] = $row[0]; } array_multisort($param, SORT_NUMERIC, SORT_DESC, $arr); print_r($arr);