I have looked at the php documentation, tutorials online and none of them how usort is actually working. I have an example i was playing with below.
$data =
The callback provided to the sorting functions in PHP have three return values:
0: both elements are the same
-1 (<0): the first element is smaller than the second
1 (>0): the first element is greater
Now, usort probably uses some kind of quicksort or mergesort internally. For each comparison it calls your callback with two elements and then decides if it needs to swap them or not.