为什么只执行了 $y=0 呢,  $y=1,$y=2,跳过去了。function count_this_bl($uid,$k,$rand_num)
{
global $_SGLOBAL;
    static $rand=0;
    static $num3;
    
    if($rand != $rand_num)
    {   
        $num3=0;
        $rand = $rand_num;        
    }
    
    static $i = 0;
    
for($i=$k;$i>0;$i--) // $k 层次
{
$result = $_SGLOBAL['db']->fetch_one('select level1,level2,level3 from uc_level where uid='.$uid);
        if($result)
        {   
            for($y=0;$y<3;$y++) //判断 L1,L2,L3 是否为空
     {
     if($result[$y])  //继续 L -> $y 下层
     {  
         $num3++;
                    echo $num3.'呵呵<br />';
     count_this_bl($result[$y],$i,$rand);                
     }
     }
        }    }
    return $num3;
}

解决方案 »

  1.   

    $result = $_SGLOBAL['db']->fetch_one('select level1,level2,level3 from uc_level where uid='.$uid);
    的到得是什么?输出一个看看
      

  2.   

    $result = $_SGLOBAL['db']->fetch_one('select level1,level2,level3 from uc_level where uid='.$uid);这个是结果:      array( 
        0=>1111,
        level1=>1111,
        1=>2222,
        level2=>2222,
        2=>3333,
        level3=>3333
    );最开始时,它执行了  array[0] ,然后就开始递归了,但是没有返回 array[1]和 array[2]再次递归。 
      

  3.   

    那就与 static $i = 0; 有关了
    注释掉就应该可以了