/*//递归
function sum($n){
if($n>1){
return $n+sum($n-1);
}else{
return 1;
}
}
echo sum(-100); //返回5050
//递归求和函数
/*sun(5) = 5+sum(4);
sum(4) = 4+sum(3);
sum(3) = 3+sum(2);
sum(2) = 2+1;*/
/*拿到题目先列已知条件 会写的先写出来 不会的再找规律*/
//用递归的方式打印出当前目录及子目录
function showDir($path,$level = 0){
$fh = opendir($path);
while(($row = readdir($fh)) !== false){
if(($row == ‘.‘)||($row == ‘..‘)){
continue;
}
$row = mb_convert_encoding($row,‘utf-8‘, "gbk");//输出转换为GBK编码
echo str_repeat(" ",$level),$row,‘<br/>‘;
if(is_dir($row)){
showDir($path.‘/‘.$row,$level+1);
}
}
closeDir($fh);
}
showDir(‘.‘);
时间: 2024-10-06 11:08:24