Home  >  Article  >  Backend Development  >  PHP implements directory operations

PHP implements directory operations

零到壹度
零到壹度Original
2018-03-26 17:47:521759browse

This time I will bring you PHP to implement directory operations. What are the precautions for PHP to implement directory operations? The following is a practical case, let's take a look.

Recursively obtain directory content

Recursion point: when the file read is a directory.

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

PHP implements directory operations

2. Determine whether each read file is a directory , if it is a directory, call it recursively, passing the current subdirectory as a parameter.

PHP implements directory operations

#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 implements directory operations
PHP implements directory operations

//str_repeat: Repeat a string and return the result of input repeated multiplier times. string str_repeat (string $input, int $multiplier)

Returns the result of input repeated multiplier times.

PHP implements directory operations
PHP implements directory operations
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 implements directory operations

Recursively delete directory contents

PHP implements directory operations


The above is the detailed content of PHP implements directory operations. 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