I get my array of data via MySQL PDO:
"select * from table"
Is it faster to order using function within query such as
"select * from table order by key"
Do I sacrifice a lot of efficiency by using a PHP usort or any other array sort compared to a straight mysql order query?
$prepare=$database->prepare("select * from table");
$prepare->execute();
$fetch=$prepare->fetchall(PDO::FETCH_ASSOC);
usort($fetch, ...)
In general mysql order works very fast and it handy to use it, but it's correct in case where you have indexes and you use that index in query for ordering data and explain of that query is good, but in some cases php sorts works really faster (i have situation where my query selects huge batch of records that group it and than having it and than order a small result by field without index).
There is no one rule for this, you should benchmark both approaches.
The problem here is with your toy example. In reality you never run a query like "select * from table". While with real live queries you never select the whole table, but just several records. So there will be just no way to sort records in PHP, and you will have to stick with sorting on mysql side, for which purpose a database were invented.