PHP deletes all files in a directory in one sentence_PHP tutorial

WBOY
Release: 2016-07-13 10:17:07
Original
784 people have browsed it

php Delete all files in the directory in one sentence

Example

The code is as follows

array_map('unlink',glob('*'));

With this sentence, you can delete files in all directories. We can also specify the directory, such as

The code is as follows

array_map('unlink',glob('aaa/*'));

It is all the files in the aa directory. Let’s talk about these three functions

The glob() function returns the file name or directory matching the specified pattern

The unlink() function deletes files

The array_map() function returns the array after the user-defined function is applied. The number of arguments accepted by the callback function should be consistent with the number of arrays passed to the array_map() function

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/895095.htmlTechArticlephp Delete all files in the directory in one sentence. The example code is as follows array_map('unlink',glob('*')) ; This sentence can delete files in all directories. We can also specify the directory, such as...
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