首页 > 其他 > 详细

递归函数你玩懂了吗?

时间:2014-07-31 13:32:26      阅读:355      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!