Heim >Backend-Entwicklung >PHP-Tutorial >php列出目录中所有子目录的实现代码

php列出目录中所有子目录的实现代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:56:131053Durchsuche
  1. /**

  2. * 取出指定目录的所有子目录
  3. * edit: bbs.it-home.org
  4. * 2013/10/9
  5. */
  6. function listdir($dir){
  7. if ($handle = opendir($dir)){
  8. $output = array();
  9. while (false !== ($item = readdir($handle))){
  10. if (is_dir($dir.'/'.$item) and $item != "." and $item != ".."){
  11. $output[] = $dir.'/'.$item;
  12. $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
  13. }
  14. }
  15. closedir($handle);
  16. return $output;
  17. }else{
  18. return false;
  19. }
  20. }
  21. //调用,取目录中的所有子目录,循环遍历。

  22. $dirs = listdir('myDirectory');
  23. foreach($dirs as $dir){
  24. echo $dir.'
    ';
  25. }
  26. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn