Skip to content
Advertisement

List all json files from folder then sort by date and paginate it

I need help to make it work. I’m using this code for list all json files from folder and paginate it and this works well.

JavaScript

But how can I implement sort by getMTime() and krsort()? I want the last modified files at first.

Advertisement

Answer

Store the mtime values in a separate array, then sort by them with usort.

Before the loop, add:

JavaScript

In the loop:

JavaScript

Then, after the loop:

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