Home > Article > Backend Development > 5 ways to implement recursive directories in PHP
This article mainly introduces 5 ways to implement recursive directories in PHP, which are mainly implemented by using some loops. Interested friends can refer to it.
During project development, it is inevitable to create folders on the server, such as the directory when uploading images, the directory when parsing templates, etc. This is not used in my current project, so I summarized several methods of creating directories in a loop.
Method 1: Use glob loop
Method 2: Use dir && read loop
read()) !== false) { $p = realpath($path . '/' . $file); if ($file != "." && $file != "..") { $arr[] = $p; } if (is_dir($p) && $file != "." && $file != "..") { myscandir2($p, $arr); } } } ?>
Method 3: Use opendir && readdir loop
Method 4: Use scandir loop
Method 5: Use SPL loop
##
getFilename(); $p = realpath($path . '/' . $file); if (!$fileinfo->isDot()) { $arr[] = $p; } if ($fileinfo->isDir() && !$fileinfo->isDot()) { myscandir5($p, $arr); } } } ?>You can use xdebug to test the running time
Redis multi-database selection function singleton class implemented in PHP (detailed explanation)
Detailed explanation of the method of PHP custom function to determine whether it is submitted by Get/Post/Ajax
phpMethod of automatically backing up the database table
The above is the detailed content of 5 ways to implement recursive directories in PHP. For more information, please follow other related articles on the PHP Chinese website!