Page 1 of 1

Need help Sorting

Posted: Wed Jul 21, 2010 12:55 pm
by mrlayance
Here is the code, but the list is not sorted properly (alphabetically)?

Code: Select all

<?php
function folderlist(){
  $startdir = './';
  $ignoredDirectory[] = '.'; 
  $ignoredDirectory[] = '..';
   if (is_dir($startdir)){
       if ($dh = opendir($startdir)){
           while (($folder = readdir($dh)) !== false){
               if (!(array_search($folder,$ignoredDirectory) > -1)){
                 if (filetype($startdir . $folder) == "dir"){
                       $directorylist[$startdir . $folder]['name'] = $folder;
                       $directorylist[$startdir . $folder]['path'] = $startdir;
                   }
               }
           }
           closedir($dh);
       }
   }
return($directorylist);
sort($directorylist);
}
$folders = folderlist();
  foreach ($folders as $folder){
    $path = $folder['path'];
    $name = $folder['name'];

    echo '<a href="'. $path . $name .'">' . $name . '</a><br />';
  }
?>
Thanks for the help.

Re: Need help Sorting

Posted: Wed Jul 21, 2010 1:13 pm
by AbraCadaver
It would help to put the sort() BEFORE the return.

Re: Need help Sorting

Posted: Wed Jul 21, 2010 1:30 pm
by mrlayance
I always miss the easy ones... Time to go home...

Thanks.