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

WBOY
Release: 2016-05-31 19:28:29
Original
1041 people have browsed it

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

代码如下:


 
//删除目录下所有空目录
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 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!