This article mainly shares with you PHP directory operation examples and recursively obtains directory contents. I hope it can help you.
Recursion point: when the file read is a directory.
1. First read the contents of a directory (excluding subdirectories):
2. Judgment Whether each read file is a directory, if so, call it recursively and pass the current subdirectory as a parameter.
#3. Indentation mode output result
The recursive call depth is the indentation level of the file determined by this function! Whenever a recursive call is made, the indentation level increases by 1 level.
//str_repeat:重复一个字符串,返回 input 重复 multiplier 次后的结果。string str_repeat ( string $input , int $multiplier )
Returns the result of input repeated multiplier times.
4. Record the results in array mode
Format:
Array( Array(‘deep’=>0, ‘filename’=>’application’), Array(‘deep’=>1, ‘filename’=>’back‘), Array(‘deep’=>1, ‘filename’=>’controllers‘[, ‘type’=’dir’]))
Recursion point: when the file read is a directory.
1. First read the contents of a directory (excluding subdirectories):
2. Judgment Whether each read file is a directory, if so, call it recursively and pass the current subdirectory as a parameter.
#3. Indentation mode output result
The recursive call depth is the indentation level of the file determined by this function! Whenever a recursive call is made, the indentation level increases by 1 level.
//str_repeat:重复一个字符串,返回 input 重复 multiplier 次后的结果。string str_repeat ( string $input , int $multiplier )
Returns the result of input repeated multiplier times.
4. Record the results in array mode
Format:
Array( Array(‘deep’=>0, ‘filename’=>’application’), Array(‘deep’=>1, ‘filename’=>’back‘), Array(‘deep’=>1, ‘filename’=>’controllers‘[, ‘type’=’dir’]))
Related recommendations:
How to use the functions of the PHP directory
Summary of php directory management functions_PHP tutorial
The above is the detailed content of PHP directory operation example. For more information, please follow other related articles on the PHP Chinese website!