Sunday, 20 February 2011

Sorting an array from library in PHP, with a Quora answer

We at the Web 3.0 Lab love PHP as much as we love Quora, which is lot. We understand both have their limits, but for getting a agile answer what could be better? So we love Quora on PHP, we often find people have already answered questions before we can raise them, like this one.

How can I get files from a directory and show them in alphabetical order with PHP?Edit

I am trying to get file names from a directory, but have the listed in alphabetical order with PHP.Edit

Yoan Blanc, freelance swiss web developer

$ php -a
php > $d = dir("/tmp");
php > $f = array();
php > while ($entry = $d->read()) { $f[] = $entry; }
php > asort($f);
php > print_r($f);

No comments:

Post a Comment