首页  >  文章  >  后端开发  >  列出目录中的所有子目录的PHP函数

列出目录中的所有子目录的PHP函数

WBOY
WBOY原创
2016-07-25 08:45:16816浏览

下面的函数列出目录中的所有子目录:

  1. function listdir($dir){
  2. if ($handle = opendir($dir)){
  3. $output = array();
  4. while (false !== ($item = readdir($handle))){
  5. if (is_dir($dir.'/'.$item) and $item != "." and $item != ".."){
  6. $output[] = $dir.'/'.$item;
  7. $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
  8. }
  9. }
  10. closedir($handle);
  11. return $output;
  12. }else{
  13. return false;
  14. }
  15. }
  16. $dirs = listdir('myDirectory');
  17. foreach($dirs as $dir){
  18. echo $dir.'
    ';
  19. }
  20. ?>
复制代码

目录中, PHP


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn