Search the blog

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);
Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.