How php traverses folders
This article focuses on "how php traverses folders". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how php traverses folders.
1. Description
Scandir returns an array that specifies the files and directories in the directory.
2. Grammar
Scandir (directory,sorting_order,context)
3. Parameters
The directory that directory specifies to scan.
Sorting_order specifies the order of arrangement.
Context specifies the directory environment.
4. Return value
If successful, an array of files and directories is returned. FALSE is returned if it fails.
5. Traverse the folder instance
/ * use scandir to traverse the directory * * @ param $path * @ return array * / function getDir ($path) {/ / determine whether the directory is empty if (! file_exists ($path)) {return [];} $files = scandir ($path); $fileItem = []; foreach ($files as $v) {$newPath = $path .directory _ SEPARATOR. V; if (is_dir ($newPath) & & $v! ='. & & $v! ='..') {$fileItem = array_merge ($fileItem, getDir ($newPath));} else if (is_file ($newPath)) {$fileItem [] = $newPath;}} return $fileItem } at this point, I believe you have a deeper understanding of "how php traverses folders". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!