码迷,mamicode.com
首页 > 其他好文 > 详细

递归函数你玩懂了吗?

时间:2014-07-31 13:32:26      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:递归

<?php


/* 
 * php递归函数的用法
 * 你玩过吗?
 * 下面开始玩一玩
 */


//自己调自己就是回调       实现了一个垒加2垒减2的效果
class digui{
    public function index($number){
         if($number>0) {
             echo $number,"&nbsp;";
             $this->index($number-2);      //自己调自己就是回调
         }
    }
    public function unindex($number1){
         if($number1<=10){
             echo $number1,"&nbsp;";
             $this->unindex($number1+2);
         }
    }
    
}
$obj = new digui();
$obj ->index(10);
echo "<br />";
$obj ->index(9);


echo "<br />";
$obj ->unindex(1);


echo "<br />";
$obj ->unindex(2);

递归函数你玩懂了吗?,布布扣,bubuko.com

递归函数你玩懂了吗?

标签:递归

原文地址:http://blog.csdn.net/qq1355541448/article/details/38312799

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!