title: Sort array using multiple criteria in PHP
body: <p>I know there are some other topics about sorting with multiple criteria, but they don't fix my problem.
  Let's say I have this array:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [uid] =&gt; 1
              [score] =&gt; 9
              [endgame] =&gt; 2
          )
  
      [1] =&gt; Array
          (
              [uid] =&gt; 2
              [score] =&gt; 4
              [endgame] =&gt; 1
          )
  
      [2] =&gt; Array
          (
              [uid] =&gt; 3
              [score] =&gt; 4
              [endgame] =&gt; 100
          )
  
      [3] =&gt; Array
          (
              [uid] =&gt; 4
              [score] =&gt; 4
              [endgame] =&gt; 70
          )
  
  )
  </code></pre>
  
  <p>I want to sort it, putting the one with the HIGHEST score on top. On same score, I want the one with the LOWEST endgame number on top.
  The sorting mechanisme should rank user1 on top, then user2, then 4 and then user3.</p>
  
  <p>I use this sorting mechanisme:</p>
  
  <pre><code>function order_by_score_endgame($a, $b)
  {
    if ($a['score'] == $b['score'])
    {
      // score is the same, sort by endgame
      if ($a['endgame'] == $b['endgame']) return 0;
      return $a['endgame'] == 'y' ? -1 : 1;
    }
  
    // sort the higher score first:
    return $a['score'] &lt; $b['score'] ? 1 : -1;
  }
  usort($dummy, "order_by_score_endgame");
  </code></pre>
  
  <p>This gives me the following array:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [uid] =&gt; 1
              [score] =&gt; 9
              [endgame] =&gt; 2
          )
  
      [1] =&gt; Array
          (
              [uid] =&gt; 3
              [score] =&gt; 4
              [endgame] =&gt; 100
          )
  
      [2] =&gt; Array
          (
              [uid] =&gt; 2
              [score] =&gt; 4
              [endgame] =&gt; 1
          )
  
      [3] =&gt; Array
          (
              [uid] =&gt; 4
              [score] =&gt; 4
              [endgame] =&gt; 70
          )
  
  )
  </code></pre>
  
  <p>As you can see, the array isn't sorted properly... Anyone knows what I'm doing wrong? Thanks a lot!</p>