<p>What is an elegant way to sort objects in PHP? I would love to accomplish something similar to this.</p>

<pre><code>$sortedObjectArary = sort($unsortedObjectArray, $Object-&gt;weight);
</code></pre>

<p>Basically specify the array I want to sort as well as the field I want to sort on. I looked into multidimensional array sorting and there might be something useful there, but I don't see anything elegant or obvious.</p>

Almost verbatim from the manual:
```
```
function compare_weights($a, $b) { 
    if($a->weight == $b->weight) {
        return 0;
    } 
    return ($a->weight < $b->weight) ? -1 : 1;
} 

usort($unsortedObjectArray, 'compare_weights');
```
```
If you want objects to be able to sort themselves, see example 3 here:
http://php.net/usort