I have a PHP script that is recursively getting files from a directory tree. Currently it is sorting by "newest added" date.
The filenames are variable, but all end in 8 digit numbers that represent yyyymmdd
So we could have
MyFileName-20180102 DifferentName3-20171231 MyName-20170704
Here's the code I have:
// Loop recursively through all directories in specified path and list all files
$files = array();
function getFiles($strDocRoot, $path, &$files) {
foreach (glob("$path/*") as $node) {
if (!is_dir($node)) {
$files[str_replace($strDocRoot, '', $node)] = filemtime($node);
} else {
getFiles($strDocRoot, $node, $files);
}
}
}
getFiles($strDocRoot, "$strDocRoot$feed", $files);
arsort($files);
What I need is to get this array sorted by those ending dates in descending order. I'm not quite sure how the arsort is determining its method of sorting.
Any help would be appreciated.