最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php递归用法与递归目录实例
时间:2013-10-17 编辑:简简单单 来源:一聚教程网
看一个简单的递归实例
例1
代码如下 | 复制代码 |
function demo($a) { static $sum=1; if($a > 1){ $sum*=$a; demo(--$a); }else{ $a=$sum; } return $sum; } echo demo(10); |
例2
代码如下 | 复制代码 |
class listdir{ function listdir($dir){ //把结果保存进多维数组 //字符窜化结果 function tostring($dir=”"){
$this->tostring.=”Directory:”.$dir.”n”; while(false!==($item=$d->read())) { if($item!=”.”&&$item!=”..”) { $path=$dir.”/”.$item; if(is_dir($path)){ $this->depth+=1; $this->tostring($path); }else{ $this->tostring.=” } } } $this->depth-=1; $d->close(); $this->tostring.=” return $this->tostring; } } $wapdir=”jquery”; $d=new listdir($wapdir); echo $d->tostring(); ?> 输出结果:
Directory:jquery Directory:jquery/d |
-
上一个: PHP $this变量一些理解
-
下一个: php怎么设置后台某IP段可以登陆?
相关文章
- php smarty 目录引擎实例入门教程 12-05
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24