if($n>1){
return $n+sum($n-1);
}else{
return 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('.');post
//遞歸階乘函數編碼
function demo($a){spa
if($a >1){blog
$r=$a*demo($a-1);遞歸
}else{utf-8
$r=$a;it
}io
return $r;function
}