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

php获取目录所有文件与所有目录保存到数组程序

WBOY
Release: 2016-06-13 11:17:46
Original
810 people have browsed it

php获取目录所有文件与所有目录保存到数组程序这是一款利用glob函数把指定目录所有的文件与文件夹保存到数据,然后我们再用foreach再判断保存到相关的数据里面哦。  

php教程获取目录所有文件与所有目录保存到数组程序
这是一款利用glob函数把指定目录所有的文件与文件夹保存到数据,然后我们再用foreach再判断保存到相关的数据里面哦。

$dirs    = array();
foreach(glob("./*") as $d)
{
    $tmp = explode('.',$d);
 $k = end($tmp);
    if(is_file($d) && $k =='php')
    {
        $dirs[]    = $d;
    }
}
print_r($dirs);

//显示目录所有目录

$v =array();
foreach(glob("./*") as $vv)
{
   // $tmp = explode('.',$d);
 //$k = end($tmp);
    if(is_dir($vv)) //目录与文件区别是就用is_dir或is_file来判断
    {
        $v[]  = $vv;
    }
}
print_r($v);

/*
结果

array
(
    [0] => ./1.php
    [1] => ./10.php
    [2] => ./11.php
    [3] => ./3.php
    [4] => ./4.php
    [5] => ./5.php
    [6] => ./7.php
    [7] => ./8.php
    [8] => ./9.php
)

array
(
    [0] => ./www.bkjia.com
)
*/


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!