Home > php教程 > php手册 > body text

使用array_map简单搞定PHP删除文件、删除目录,

WBOY
Release: 2016-06-13 09:22:40
Original
868 people have browsed it

使用array_map简单搞定PHP删除文件、删除目录,

废话不多说,直接贴上代码。本文体现的就是简洁

复制代码 代码如下:


 
//删除目录下所有空目录
array_map('rmdir', glob('*', GLOB_ONLYDIR));
 
//删除目录所有文件
array_map('unlink', array_filter(glob('*'), 'is_file'));

使用array_map实现array_column功能:

复制代码 代码如下:


$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);

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 Recommendations
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!