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);
php显示目录所有目录,代码如下:
- $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.phpfensi.com
- )
- */