I have an array of Town objects, and then another object (City) which contains a sort for the first object.
Class City
{
$id
$name
$towns
$town_id_order
//etc
}
Class Town
{
$id
$name
//etc
}
So I need to be able to sort the Town based on the City->town_id_order
I'm guessing this is usort but I cannot get it to work with objects as the sort.
This is what I've tried , but returns 'Expects array not string'
function cmp($a, $b)
{
if ($a == $this->towns) {
return 0;
}
return ($a < $this->towns) ? -1 : 1;
}
$a = $this->getTownsOrder();
usort($a, "cmp");