i want preg_match to find all files in a given directory and display them on a page. I know how to do that but how do i sort them by date of CREATION? I want the newest one on top. This is my code:
function find_files() {
$files = scandir("content");
foreach ($files as $value) {
if(preg_match("/file/", $value)) {
echo "<li>$value</li>";
}
}
}
Thank you.
EDIT: according to the answers i got i modified my code like this:
function find_files() {
$files = scandir("content");
usort($files, create_function('$a,$b', 'return filectime($a)<filectime($b);'));
foreach ($files as $value) {
if(preg_match("/file/", $value)) {
echo "<li>$value</li>";
}
}
}
However it still wont work. The browser wont finish loading.