如何解决阵容问题?
<>>收到结果:
Array
(
[0] => 2011/03/13
[1] => 2011/03/14
[2] => 2011/02/21
)
现在我未能取得以下成果:
Array
(
[0] => 2011/03/13
)
Array
(
[0] => 2011/03/14
)
Array
(
[0] => 2011/02/21
)
<>蓬皮>
<?php
function get_dir_iterative($dir= . ,$exclude=array( cgi-bin , . , .. )){
$exclude=array_flip($exclude);
if(!is_dir($dir)){return;}
$dh=opendir($dir);
if(!$dh){return;}
$stack=array($dh);
$level=0;
while(count($stack)){
if(false!==($file=readdir($stack[0]))){
if(!isset($exclude[$file])){
if(is_dir("$dir/$file")){
$dh=opendir("$file/$dir");
if($dh){
$d=$file;
array_unshift($stack,$dh);
++$level;
}
}else{
if(isset($d)&&$level>0){
$mod=date( Y/m/d ,filemtime("$d/$file"));
$ds="$d/";
}else{
$mod=date( Y/m/d ,filemtime($file));
$ds= ;
}
$array=array($mod);
//$b=array_merge($array); // it doesn t solve the problem
print_r($array);
}
}
}else{
closedir(array_shift($stack));
--$level;
}
}
}
get_dir_iterative();
?>
Update:
On replacing $array=array($mod);
with $array[]=$mod;
does not return excepted result.
Array
(
[0] => 2011/03/13
)
Array
(
[0] => 2011/03/13
[1] => 2011/03/14
)
Array
(
[0] => 2011/03/13
[1] => 2011/03/14
[2] => 2011/02/21
)