Sort name of php file

Asked

Viewed 32 times

0

I have a php code, which I use to make files available to clients, but I need it to sort the file name from the largest to the smallest, for example, I have the files:

2019 Arquivo 1

2018 Arquivo 2

2017 Arquivo 3

I need them to take this ordination.

<?php
foreach (glob("*.pdf") as $arquivo) {
    echo "<a href='$arquivo'>$arquivo</a><br>" ;

}
?>

1 answer

1


Use "rsort" to sort down the list of files returned by "glob". For example:

$lista = glob("*.pdf");
rsort($lista);
foreach ($lista as $arquivo) {
    echo "<a href='$arquivo'>$arquivo</a><br>" ;
}

The result will be:

2019 Arquivo 1.pdf
2018 Arquivo 2.pdf
2017 Arquivo 3.pdf
  • It worked right, thank you very much, big hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.