2

Is it possible to sort opendir into althabetical order?

$user = $fgmembersite->UserFullName();
$handle = opendir("users/$user/");

while (false!==($file = readdir($handle))) {
    if ($file != "." && $file != ".."){
        echo 'some code here';
    }
}

Thanks in advance!

Josh
  • 8,082
  • 5
  • 43
  • 41
Josh
  • 2,835
  • 1
  • 21
  • 33
  • I asked a very similar question... http://stackoverflow.com/questions/541510/php-readdir-not-returning-files-in-alphabetical-order – Buggabill Mar 23 '12 at 17:49

1 Answers1

6

I would use scandir() instead:

$user = $fgmembersite->UserFullName();
$files = scandir('users/' . $user . '/');
foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
        // Do stuff here
    }
}

As Blauesocke pointed out, it is already sorted.

Brad
  • 159,648
  • 54
  • 349
  • 530