title: Sort a php array in a custom order
body: <p>I have a table called "car_owners", it has three columns known as:</p>
  
  <pre><code>id  owner   cars
  1   Greg    1
  2   Gary    3
  3   Aaron   2
  4   Farb    3
  5   REX     1
  6   Fred    2
  </code></pre>
  
  <p>In the following code I get it into array and print it:</p>
  
  <pre><code>$exc = $conn-&gt;prepare("SELECT name,state from current_state");
          $exc-&gt;execute();
              while($finalResult = $exc-&gt;fetch(PDO::FETCH_ASSOC))
               {
                          $tables[] = $finalResult;
               }
  var_dump($tables);
  </code></pre>
  
  <p>once i get this into an array, <strong>is there a way i could sort it in a custom order where i could get the out put like follows,
  first the owners with 2 cars, then with 1 car and who has 3</strong></p>
  
  <pre><code>owner   cars
  Aaron   2
  Fred    2
  Greg    1
  REX     1
  Farb    3
  Gary    3
  </code></pre>
  
  <p><strong>P.S doing it from the table is not going to work, because im using a loop above the code which makes it impossible to do it from the SQL, can anybody tell me a way to do it from the php</strong></p>