File Directory Php

function RecurseDir($basedir, $AllDirectories=array()) {
#Create array for current directories contents
$ThisDir=array();
#switch to the directory we wish to scan
chdir($basedir);
$current=getcwd();
#open current directory for reading
$handle=opendir(".");
while ($file = readdir($handle)) {
#Don't add special directories '..' or '.' to the list
if (($file!='..') & ($file!='.')) {
if (is_dir($file)) {
#build an array of contents for this directory
array_push($ThisDir,$current.'/'.$file);
}
}
}
closedir($handle);
#Loop through each directory, run RecurseDir function on each one
foreach ($ThisDir as $key=>$var) {
array_push($AllDirectories, $var);
$AllDirectories=RecurseDir($var, $AllDirectories);
}
#make sure we go back to our origin
chdir($basedir);
return $AllDirectories;
}
?>
/* example */
$dirlist=RecurseDir("/home/ben");
foreach ($dirlist as $key=>$val) {
echo $val;
}
?>