I have an array $scores
as per below.
What I am trying to do is sort the array based on the numeric value in a descending order. I've tried defining functions like suggested here and other ways but haven't been able to do it. Any help or guidance is much appreciated.
------------------------------------------------------------updated------------------------------------------------------------
array ( 0 => array ( 0 => 'B.Howell', 1 => 16.8, ), 1 => array ( 0 => 'B.Osweiler', 1 => 14.88, ), 2 => array ( 0 => 'K.Ballage', 1 => 13.7, ), 3 => array ( 0 => 'F.Owusu', 1 => 8.8, ), 4 => array ( 0 => 'I.Ford', 1 => 6.3, ), 5 => array ( 0 => 'B.Radcliff', 1 => 6.4, ), 6 => array ( 0 => 'D.Fales', 1 => 3.96, ), 7 => array ( 0 => 'L.Carroo', 1 => 4.9, ), 8 => array ( 0 => 'R.Scott', 1 => 2.5, ), 9 => array ( 0 => 'M.Lewis', 1 => 2.4, ), 10 => array ( 0 => 'T.Duarte', 1 => 3.2, ), 11 => array ( 0 => 'J.Langford', 1 => 2.8, ), 12 => array ( 0 => 'A.Derby', 1 => 1.1, ), 13 => array ( 0 => 'D.Morgan', 1 => 1.2, ), )
The solutions offered using usort
I've tried previously and could not get them to work and still can't. It does tend to sort the array in somewhat of a descending order, however, there still exists outliers, see the following before and after images.
function mySort($a, $b) {
return $b[1] - $a[1];
}
usort($scores, 'mySort');