FrozenTime FrozenTime - 1 year ago 148
PHP Question

glob() — Sort by Name

How can I reverse the sort by filename? Currently it displays all the text files in alphabetical / numerical order, but I'm trying to have it display in descending order instead. Right now, I have...

foreach (glob("*.txt") as $filename) {

I'm pretty new to PHP, but I tried usort with array added on but that just resulted in it displaying only 1 of the text files, so either that doesn't work or I just coded it wrong.

Answer Source

You can use array_reverse:

foreach(array_reverse(glob("*.txt")) as $filename) { ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download