 <p>If you MUST sort the array in PHP, after you got the query result, use the <code>array_multisort</code> function in PHP (<a href="http://www.php.net/manual/en/function.array-multisort.php" rel="nofollow">http://www.php.net/manual/en/function.array-multisort.php</a>)</p> <p>However, if your life does not depend on sorting in PHP, sort at the source in your SQL (the way God intended it to be) it's going to be much much faster and it will take the load off the web server.</p> <p>Hope this helps.</p>