PHP directory operation example

小云云
Release: 2023-03-22 12:16:01
Original
1586 people have browsed it

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 )
Copy after login
Copy after login

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’]))
Copy after login
Copy after login

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 )
Copy after login
Copy after login

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’]))
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!