話很少說,直接上代碼php
<?php function my_dir($dir) { $files = []; if(@$handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != ".." && $file != ".") { if(is_dir($dir . "/" . $file)) { //若是是子文件夾,進行遞歸 $files[$file] = my_dir($dir . "/" . $file); } else { $files[] = $file; } } } closedir($handle); } return $files; } echo "<pre>"; print_r(my_dir("./")); echo "</pre>";