php - Multidimensional array sort on multiple keys -
php - Multidimensional array sort on multiple keys -
hi i've been using array_sort()
function found here time sort results multiple apis have need sort 2 keys simultaneously.
the 2 keys need sort on deal_score
desc , date_start
desc
the properties of array follows. record 2 has highest deal_score
should come first records 0 , 1 have same deal_score
date_start
higher on record 1 final order of results should 2, 1, 0
here's illustration array has been trimmed downwards readability.
[0] => array ( [db_id] => 414314 [date_start] => 2012-04-17 [deal_score] => 81.3 [deal_statements] => array ( [0] => 49.85 [1] => 2.11 ) ) [1] => array ( [db_id] => 414409 [date_start] => 2012-04-20 [deal_score] => 81.3 [deal_statements] => array ( [0] => 28.2 [1] => 21.41 ) ) [2] => array ( [db_id] => 1345923 [date_start] => 2012-04-17 [deal_score] => 85 [deal_statements] => array ( [0] => 18.1 [1] => 22.16 ) )
any help on appreciated.
sth. should do:
foreach ($data $key => $row) { $score[$key] = $row['deal_score']; $dates[$key] = $row['date_start']; } array_multisort($score, sort_asc, $dates, sort_asc, $data);
3rd. illustration on http://php.net/manual/en/function.array-multisort.php pretty much explains it.
cheers.
php sorting multidimensional-array
Comments
Post a Comment