I have the following usort
s on an array of objects. I would expect the array to be primarily sorted by the second sort, and any ties to be sorted by the first (ie, stay where the first sort has left them).
usort($arr, function($a, $b) { return ($a->best->notout < $b->best->notout) ? 1 : (($a->best->notout > $b->best->notout) ? -1 : 0); });
usort($arr, function($a, $b) { return ($a->best->runs < $b->best->runs) ? 1 : (($a->best->runs > $b->best->runs) ? -1 : 0); });
They both work fine on their own (tested by commenting out the other one), but when used together the results are unexpected in as far as the equal results on the second sort don't either default to the first sort or return the same result as the just the second sort.
Like I say the first sort works as expected, so after a lot of fiddling around I still haven't found a satisfactory answer.
Any ideas?