下面的函数列出目录中的所有子目录:
- <?php
- function listdir($dir){
- if ($handle = opendir($dir)){
- $output = array();
- while (false !== ($item = readdir($handle))){
- if (is_dir($dir.'/'.$item) and $item != "." and $item != ".."){
- $output[] = $dir.'/'.$item;
- $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
- }
- }
- closedir($handle);
- return $output;
- }else{
- return false;
- }
- }
- $dirs = listdir('myDirectory');
- foreach($dirs as $dir){
- echo $dir.'<br>';
- }
- ?>
来源: http://www.phpxs.com/code/1003344/