title: Sort Array based on multiple values
body: <p>I need to sort an array of objects based on the objects properties. Basically if you take a look at <a href="http://developers.fifteendigital.co.uk/tests/example/" rel="nofollow noreferrer">this</a> fixture table and note "Liverpool FC" and "Manchester City FC" you can see that they have the same amount of points, so they are ordered based on the other values being higher. </p>
  
  <p>Now if you take a look at <a href="http://developers.fifteendigital.co.uk/tests/8gys2/" rel="nofollow noreferrer">mine</a> i'm only ordering based on the points, i'm not sure how to order this based on multiple values. </p>
  
  <p>The data is stored within an instance of a class, this instance is stored within an <code>Array(</code>) with the <code>Key</code> being the team name. </p>
  
  <p>Below is the class which managed the data, how can I re-arrange the array so that the objects are in order the way the first link has them ordered? </p>
  
  <pre><code> class Calc {
      private $config;
      public $win = 0, $draw = 0, $loss = 0, $goalFor = 0, $goalConc = 0;
  
      public function __construct($payload = array(0,0)) {
        // Load config file
        $this-&gt;config = parse_ini_file('config.ini', true);
  
        // Add wins, losses, draws, goals for and goal conceived
        $this-&gt;addData($payload);
      }
  
      // Linked data updated, ammend values
      public function calcPlays() {
        return 0 + $this-&gt;win + $this-&gt;draw + $this-&gt;loss;
      }
      public function calcPoints() {
        // Add 0 to ensure value is an int
        return $this-&gt;win * ($this-&gt;config['winPoints']) + ($this-&gt;draw * $this-&gt;config['drawPoints']) + ($this-&gt;loss * $this-&gt;config['lossPoints']);
      }
      public function calcGoalDifference() {
        return ($this-&gt;goalFor - $this-&gt;goalConc);
      }
  
      public function addData($data) {
        // Append goal data
        $this-&gt;goalFor += $data[0];
        $this-&gt;goalConc += $data[1];
  
        // Win, Loss or Draw
        if ($data[0] &gt; $data[1]) { $this-&gt;win++;} elseif
        ($data[0] &lt; $data[1]) { $this-&gt;loss++;} elseif
        ($data[0] == $data[1]) { $this-&gt;draw++;}
      }
    }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>My data is now everywhere:</p>
  
  <pre><code>1   Burnley FC  13  4   2   7   12  21  -9  14
  2   Leicester City FC   13  3   4   6   16  22  -6  13
  3   Crystal Palace FC   13  3   2   8   21  26  -5  11
  4   Swansea City FC 13  2   3   8   16  26  -10 9
  5   Arsenal FC  13  8   4   1   28  13  15  28
  </code></pre>
  
  <p>I'm assuming my checks are the wrong way around, I was assuming it would check if <code>$a</code> is bigger than or equal to <code>$b</code>, if so then return true, if not move on to the next check?</p>
  
  <p>The code:</p>
  
  <pre><code>// Sort teams by points
  uasort($teamData, function($a, $b) {
    if ($a-&gt;calcPoints() &lt; $b-&gt;calcPoints() &amp;&amp; $a-&gt;calcPoints() !== $b-&gt;calcPoints()) {
      return true;
    } elseif ($a-&gt;calcGoalDifference() &lt; $b-&gt;calcGoalDifference() &amp;&amp; $a-&gt;calcGoalDifference() !== $b-&gt;calcGoalDifference()) {
      return true;
    } elseif($a-&gt;goalConc &lt; $b-&gt;goalConc) {
      return true;
    }
    return false;
  });
  </code></pre>