Home >Backend Development >PHP Tutorial >Use array_map to simply delete files and directories in PHP, _PHP tutorial

Use array_map to simply delete files and directories in PHP, _PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:15:441119browse

Use array_map to easily delete files and directories in PHP,

Without further ado, let’s just paste the code. This article embodies simplicity

Copy code The code is as follows:


//Delete all empty directories under the directory
array_map('rmdir', glob('*', GLOB_ONLYDIR));

//Delete all files in the directory
array_map('unlink', array_filter(glob('*'), 'is_file'));

Use array_map to implement array_column function:

Copy code The code is as follows:

$data = array(
array(
         'a' => 'first a',
'b' => 'first b'
),
array(
'a' => 'second a',
'b' => 'second b'
)
);

$array_column = array_map(function($element){
Return $element['a'];
}, $data);

print_r($array_column);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/902775.htmlTechArticleUse array_map to simply delete files and directories in PHP. Without further ado, just paste the code. This article embodies simplicity. Copy the code. The code is as follows: php //Delete all in the directory...
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