Unless you're planning on doing something in particular with the output (such as building your own file browser), the easiest way to use this is to direct the output through print_r(), which does a nice job with arrays.
I keep meaning to build a recursive version of this - it would be pretty trivial with the is_dir() function, I just haven't got around to it :-)
function dirList ($directory)
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
