I'm using scandir() on a webpage to populate a list of archived threads for a Wakaba image board. Because of the numbers, the webpage files display in a weird order.
The page is here: http://sturmkrieg.ru/img/archive/
The source is here: https://gist.github.com/Pavelovich/0f840516f6c2f14986ef
You can sort the scandir() array and then use your for (or foreach). Specifically, check out the 'sorting_order' parameter. PHP's guide might help you in this case: