This function was written by someone else, I sorted it out. Added a lot of comments.
Function description:
This function execution process:
Detect directory->Open directory->Read directory->Remove special directory->Determine whether files still exist in the subdirectory->If so, repeat Call ->If not, put the file entry into the array->Close the folder->Return the folder entry.
/**
* Display the read directory in the form of an array
* @return array
* The opendir() function opens a directory handle, which can be used by closedir(), readdir() and rewinddir().
* The is_dir() function checks whether the specified file is a directory.
* The readdir() function returns the entry in the directory handle opened by opendir().
*/
function my_scandir($dir)
{
( $dir))
while(($file=readdir($handle))!==false )
{去 // Remove special directory
if ($ file! = "&& $ file! =" .. ") {
// Judging whether the subdirectory still exists in the subdirectory
iF (IS_DIR ($ dir. "/".$file))
($dir."/".$file);
/ /Get directory array
’ s ’ s } 1 - } } } ;
The above introduces a php function that can traverse all files and subfolders in a folder. , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.