Skip to content
Advertisement

How to sort files by date in PHP

I currently have a script which allows me to output the list of files inside the same directory.

The output shows the names, and then I used filemtime() function to show the date when the file was modified.

How will I sort the output to show the latest modified file?

This is what I have for now:

JavaScript

Advertisement

Answer

You need to put the files into an array in order to sort and find the last modified file.

JavaScript

Not tested, but that’s how to do it.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement