Forum Moderators: coopster
I've got the following code which lists quite simply the folders in a sub-folder.
<?php
getDirectory('testfolder');
function getDirectory( $path = '.', $level = 0 )
{
$ignore = array( '.', '..');
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) )
{
if( !in_array( $file, $ignore ) )
{
if(is_dir( "$path/$file" ) )
{
echo "<a href='$path/$file/index.php'>$file</a><br />";
}
}
}
closedir( $dh );
}
?>
However, is it possible to list those folders in alphabetical order? I'm guessing put them into an array of somesort, but im not sure how to do that, and then sort the array using the sort() function, is that the best way of going about it?
Thanks
:)
If you are using PHP5 then you can use scandir [php.net] which will put the files into an array for you and sort it!
Andrew