Properly sorting multidimensional array using usort and spaceship operator
问题 I need to sort the following array with following logic: If the 'score' is the same, I want to compare using 'time'. The array is as follows: $user_scores = [ 82 => [ 'score' => 1, 'time' => 6.442 ], 34 => [ 'score' => 1, 'time' => 5.646 ], 66 => [ 'score' => 3, 'time' => 1.554 ] ] The 'keys' in the above array are the 'user_ids', which I need to preserve in the sorted array. My best attempt so far is as below - $result = usort( $user_scores, function ( $a, $b ) { if ( $a['score'] == $b[