递归函数你玩知道呢?

<?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);

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/hrhguanli/p/4665716.html