I have a collection of country objects that look like this:
class country {
public $uid;
public $name;
}
Now I should sort them. One country with id == 999 should always be first in the collection, the rest should be sorted by name. So, I thought usort should actually do the trick, but the sorting is not correct. I tried this:
function mySortCallback($a, $b) {
if($a->uid == 999 || $b->uid == 999) return 1;
return strcmp($a->name, $b->name);
}
usort($myCollection, 'mySortCallback');