0

I have variable $set when print_r i got this

Array ( [id] => 1000457639 
    [external_id] => 
    [auto_code_start] => 0 
    [auto_code_end] => 0 
    [code_start] => 8649 
    [home] => M.Tomas 
    [away] => MIB 
    [team_1_id] => 12318 
    [team_2_id] => 11357 
    [code] => 8639 
    [round] => 280 
    [date_time] => 2017-11-26 17:00:00 
    [date_time_short] => 26.Noe 17:00 
    [date_csv] => 26.11.17 
    [date] => 26.11.2017
    [time] => 17:00 
    [league] => Players Aba Liga 
    [league_original] => AbaLiga 
    [league_id] => 1146 
    );

Array ( [id] => 100034639 
    [external_id] => 
    [auto_code_start] => 0 
    [auto_code_end] => 0 
    [code_start] => 8629 
    [home] => C.Black 
    [away] => CIB 
    [team_1_id] => 12318 
    [team_2_id] => 11357 
    [code] => 8639 
    [round] => 280 
    [date_time] => 2017-11-26 17:00:00 
    [date_time_short] => 26.Noe 17:00 
    [date_csv] => 26.11.17 
    [date] => 26.11.2017
    [time] => 17:00 
    [league] => Players Aba Liga 
    [league_original] => AbaLiga 
    [league_id] => 1146 

     );

How can i sort this array to get the same array ($set) with [away] field ascending? The array can have more then 30 arrays. I tried ksort, usort and other know functions, but i can't have the result that i need.

Sun Moj
  • 1
  • 1

1 Answers1

0

Try this :

function sort($a, $b) {
    return $a['away'] - $b['away'];
}

usort($set, 'sort');
Vincent Decaux
  • 7,375
  • 3
  • 37
  • 52