The default sort is using SORT_REGULAR .
This takes values ββand compares them as described on the manual page. In the case where the string keys in your example are compared to zero; these strings are converted to numbers (all 0 ) for comparison. If two members are compared as equal, their relative order in the sorted array is undefined. (Quote from the usort () page.)
If you want the sorted output to have numbers before the letters, you should use SORT_NATURAL with PHP 5.4. SORT_STRING also complete the task only if the numbers remain single.
SORT_NATURAL (PHP 5.4 or later) gives keys ordered as:
0,1,2,4,11,a,b,c
SORT_STRING provides keys ordered as:
0,1,11,2,4,a,b,c
An alternative to SORT_NATURAL for PHP less than 5.4 would use uksort() .
uksort($a, 'strnatcmp');
source share