- I need to get the files in a directory in an array.
- Only files that end in .markdown
- The files should be sorted by date created
Efficiency is not a huge deal, but I always like to make things as efficient as possible. There will be multiple directories with up to a couple hundred files in each.
I know I use the scandir function to get the files into an array, but I’m not sure where to go from there. I could throw it in a loop to check if the files end in .markdown, but is there some sort of regex I could pass in to the scan?
Thanks
You can use
glob()to get an array of filenames then useusort()andfilectime()to order them by their creation dates:For PHP versions lower than 5.3: