read dir not in the file system order [duplicate] read dir not in the file system order [duplicate] codeigniter codeigniter

read dir not in the file system order [duplicate]


Looks like you're suffering from lexicographic sorting.

What you need is natsort().

Alphabetical:

1, 10, 2, 3

Natsort:

1, 2, 3, 10

The reason for this is because the elements in your array are treated as strings, so every character in the string is treated as a character and not an integer.

Further reading.