protected function sort($array, $property, $ascending)
{
$isAllEqual = true;
// going to use this to still simulate a sort if all values are equal
usort($array, function ($a, $b) use($property, $ascending, &$isAllEqual) {
$cmp = strcmp($a->{$property}(), $b->{$property}());
if ($cmp != 0) {
$isAllEqual = false;
}
return $ascending ? $cmp : -$cmp;
});
// if all values equal and sort is descending just reverse the results..
if ($isAllEqual && !$ascending) {
return array_reverse($array);
}
return $array;
}