Which do you think is faster in a PHP script:
$query = 'SELECT... FROM ... ORDER BY first_val';
or
while($row = odbc_fetch_array($result)) $arrayname[] = array( 'first_key' => $row['first_val'], 'second_key' => $row['second_val'], etc... ); sort($arrayname);
It depends on so many factors that I don’t even know what to begin with.
But as a rule, you perform sorting on database side.
Indexes, collations and all this, they help.