Custom Sorting with usort in PHP - Numerical sort with 0 at the end of the list

Delapsp

New Member
For the last couple of days i tried to get my head around the following:I have a 2-dimensional Array and i try to sort it with a custom algorithm using usort().My Problem is, that I'm trying to sort numbers like in the order of 1 2 3 0 so the zero should always be the last item.\[code\]function customsort($e1, $e2) { if ($e1["number"] == $e2["number"]) { return $e1["year"] - $e2["year"]; } elseif ($e1["number"] == 0) { return 1; } else { return $e1["number"] - $e2["number"]; }}\[/code\]I thought this would do the trick but only a part of the entrys with a zero got sorted to the end of the list. I'm pretty shure, that the list is not corrupt and dumping the whole array shows me, that every used entry delivers a zero where it should be, but they are not sorted the right way.Thanks in advance,Johnny
 
Back
Top