Home  >  Article  >  Backend Development  >  PHP function to list all subdirectories in a directory

PHP function to list all subdirectories in a directory

WBOY
WBOYOriginal
2016-07-25 08:45:16816browse

The following function lists all subdirectories in a directory:

  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.'< ;br>';
  19. }
  20. ?>
Copy code

Directory, PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn