Home >Backend Development >PHP Tutorial >PHP directory operation example

PHP directory operation example

小云云
小云云Original
2018-03-27 12:09:081635browse

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):

PHP directory operation example

2. Judgment Whether each read file is a directory, if so, call it recursively and pass the current subdirectory as a parameter.

PHP directory operation example

#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.

PHP directory operation example
PHP directory operation example

//str_repeat:重复一个字符串,返回 input 重复 multiplier 次后的结果。string str_repeat ( string $input , int $multiplier )

Returns the result of input repeated multiplier times.

PHP directory operation example
PHP directory operation example
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’]))

PHP directory operation example

Recursive deletion Directory content

PHP directory operation example

#Recursively obtain directory content

Recursion point: when the file read is a directory.

1. First read the contents of a directory (excluding subdirectories):

PHP directory operation example

2. Judgment Whether each read file is a directory, if so, call it recursively and pass the current subdirectory as a parameter.

PHP directory operation example

#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.

PHP directory operation example
PHP directory operation example

//str_repeat:重复一个字符串,返回 input 重复 multiplier 次后的结果。string str_repeat ( string $input , int $multiplier )

Returns the result of input repeated multiplier times.

PHP directory operation example
PHP directory operation example
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’]))

PHP directory operation example

Recursive deletion Directory content

PHP directory operation example

Related recommendations:

How to use the functions of the PHP directory

PHP directory operations

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!

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