FooKelvin Posted October 25, 2015 Share Posted October 25, 2015 Hi, i would like to sort the total and name with different type of sorting. uasort($data, function($a, $b) { $total = $b['total'] - $a['total']; //SORT BY DESC if($total === 0) { return strcmp($b['emp'], $a['emp']); // THIS line need to sort by ASC } return $total; }); Sort Total by DESC at the same time, sort emp BY ASC Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 25, 2015 Solution Share Posted October 25, 2015 Just swap the $a and $b round uasort($data, function($a, $b) { $total = $b['total'] - $a['total']; //SORT BY DESC if($total === 0) { return strcmp($a['emp'], $b['emp']); // THIS line now sorts by ASC } return $total; }); Quote Link to comment Share on other sites More sharing options...
FooKelvin Posted October 26, 2015 Author Share Posted October 26, 2015 Thanks Barand! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.