I'm using usort()
and filemtime()
to sort files by modification date, but it randomly returns files in the wrong order. I guess I'm missing something really simple but I can't figure out what.
usort($user_files, function($a, $b) {
return filemtime($a) > filemtime($b);
});
foreach ($user_files as $f) {
echo $f . "<br />";
}
After that I upload the file. Complete code.
When uploading the files 1.txt
... 10.txt
to test what was going on the results displayed were:
6.txt
5.txt
4.txt
3.txt
2.txt
1.txt
7.txt Uploaded!
As expected. Then, when I reached 8.txt
:
6.txt
7.txt
5.txt
4.txt
2.txt
3.txt
1.txt
8.txt Uploaded!
Another time it was fine until I reached 10.txt
:
7.txt
8.txt
9.txt
6.txt
5.txt
2.txt
3.txt
4.txt
1.txt
10.txt Uploaded!
While ls -t
returned:
10.txt 9.txt 8.txt 7.txt 6.txt 5.txt 4.txt 3.txt 2.txt 1.txt
So... What's going on there?
Debian Wheezy 7.4, up-to-date.
PHP Version 5.4.4-14+deb7u8
Linux pc 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64
FPM/FastCGI
nginx/1.2.1