<?php
function sort_objects_by_total($a, $b) {
if($a->total_posts == $b->total_posts){ return 0 ; }
return ($a->total_posts < $b->total_posts) ? -1 : 1;
}
// The function returns -1 (smaller than), 0 (equal to), or 1 (larger than)
// when doing the sort comparisons. The last is applying the sortation
// function to the array, which is done by usort:
usort($users, 'sort_objects_by_total');