Home > Article > Backend Development > PHP deletes all files in a directory in one sentence_PHP tutorial
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