When you sort()
an array in PHP you may have found that numbers are not ordered in the way you expect. For example, the string 10
will appear before the string 2
. To fix this, you need to use “natural” sorting. Either of the following lines of code will accomplish this for you:
sort($array, SORT_NATURAL);
natsort($array);
