title: Properly sorting multidimensional array using usort and spaceship operator
body: <p>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:</p>
  
  <pre><code>$user_scores = [ 82 =&gt; [ 'score' =&gt; 1, 'time' =&gt; 6.442 ],
                   34 =&gt; [ 'score' =&gt; 1, 'time' =&gt; 5.646 ],
                   66 =&gt; [ 'score' =&gt; 3, 'time' =&gt; 1.554 ]
                 ]
  </code></pre>
  
  <p>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 -</p>
  
  <pre><code>$result = usort( $user_scores, function ( $a, $b ) {
      if ( $a['score'] == $b['score'] ) {
          return $a['time'] == $b['time'];
          }
      return $a['score'] &lt;=&gt; $b['score'];
  } );
  </code></pre>
  
  <p>Obviously, this isn't working, and I'm getting the $user_scores array with all keys replaced with 0, 1, 2 instead of user_ids ( 82, 34 and 66 ). The sorting ain't working either. </p>
  
  <p>For the above array, my desired output would be $user_scores array :</p>
  
  <pre><code>$user_scores = [ 34 =&gt; [ 'score' =&gt; 1, 'time' =&gt; 5.646 ],
                   82 =&gt; [ 'score' =&gt; 1, 'time' =&gt; 6.442 ],
                   66 =&gt; [ 'score' =&gt; 3, 'time' =&gt; 1.554 ]
                 ]
  </code></pre>
  
  <p>Would really appreciate if you could tell me how to make this work using the spaceship operator (if it makes sense). Thank you for your time and I look forward to your responses. </p>
  
  <p>---UPDATE ---</p>
  
  <p>The sorting logic required is like this:</p>
  
  <ol>
  <li>Higher the score, higher would be the rank.</li>
  <li>Higher the time, lower would be the rank. </li>
  </ol>
  
  <p>It's basically sorting the results of quiz. The top scorers with the least amount of time would be at the top; and those with lower score and higher time would be at the bottom. </p>