I have an array that is populated from the function iterator_to_array. After I sort it (tried asort()
, ksort()
and rsort()
and all of them show the same result: an out of order array...
This is my code.
$fi = new FilesystemIterator($location, FilesystemIterator::SKIP_DOTS);
$file_paths = iterator_to_array( $fi, false);
rsort($file_paths);
echo "<pre>", print_r($file_paths), "</pre>";
The print_r
returns:
Array
(
[0] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => /opt/lampp/htdocs/majo/log_files/teste/log2014324.txt
[fileName:SplFileInfo:private] => log2014324.txt
)
[1] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => /opt/lampp/htdocs/majo/log_files/teste/log2014325.txt
[fileName:SplFileInfo:private] => log2014325.txt
)
[2] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => /opt/lampp/htdocs/majo/log_files/teste/log2014323.txt
[fileName:SplFileInfo:private] => log2014323.txt
)
[3] => SplFileInfo Object
(
[pathName:SplFileInfo:private] => /opt/lampp/htdocs/majo/log_files/teste/log2014322.txt
[fileName:SplFileInfo:private] => log2014322.txt
)
)
After a routine to clear the name of the file I get this output:
2014324.txt
2014325.txt
2014323.txt
2014322.txt
However because of rsort()
(the function used at that time) it should be:
2014325.txt
2014324.txt
2014323.txt
2014322.txt
Everytime the 2014325.txt
is out of place and I can't seem to get it in place, does anyone know how to fix this?
I can implement a solution that involves doing the sorting in a manual way, but it will spend a lot more time and resources, however.
PS: ksort()
output:
2014322.txt
2014323.txt
2014325.txt
2014324.txt