Josh
Josh

Reputation: 2895

Sort opendir In Alphabetical Order

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!

Upvotes: 2

Views: 3705

Answers (1)

Brad
Brad

Reputation: 163232

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.

Upvotes: 6

Related Questions