function fuc_location($ID,$location){
    global $table_class;
  //if(!$ID){ print_r($location); return $location;}   
if($ID){
          $sql="select * from $table_class where ID=$ID";
  $result=mysql_query($sql) or die(mysql_error());
          $row1 = mysql_fetch_array($result);
          $location[]=$row1["ID"]."".$row1["class_name"]."";

  fuc_location($row1["parentID"],$location); //
       }else{
          print_r($location);return $location;}} 
请问一下为什么我print_r 输出的值是对的,然后想马值 $location return就是return不出来.谢谢,望高手赐教!!!

解决方案 »

  1.   

    ??这么清楚还不知所云??? 看最后一句,print_r($location);return   $location;}  print_r出来的值是有的 但是用return,函数就是没值回去.:(
      

  2.   

    确实不知道楼主在说什么,呵呵,给两个回答,1,return是返回值,而不会打印出来,2,$location好象是数组,如果是数组要打印不可以直接echo $location.
      

  3.   

    晕了,这么明白还听不懂,我用return是出不来值的 所以用print_r打印看看是有值的,明白了吗,超级晕晕...
      

  4.   

    如果return出来有值我就不用问了,就是不出,但是我用print_r打印值是有的,这回应该明白了吧,不明白本人也没办法,望高人指点!!
      

  5.   

    lz知不知道什么是局部变量?你应该将$location设为静态变量或者全局变量,这样在整个递归调用中都会应用同一个变量.
      

  6.   

    改写试试:function   fuc_location($ID){ 
            global   $table_class; 
            static $location = array();    //if(!$ID){   print_r($location);   return   $location;}       
    if($ID){ 
                        $sql="select   *   from   $table_class   where   ID=$ID"; 
        $result=mysql_query($sql)   or   die(mysql_error()); 
                        $row1   =   mysql_fetch_array($result); 
                        $location[]=$row1["ID"]."".$row1["class_name"]."";     fuc_location($row1["parentID"]);   // 
                  }else{ 
                        print_r($location);return   $location;} }   
      

  7.   

    应该不要else,否则无法return.
    function  fuc_location($ID){   
                    global       $table_class;   
                    static   $location   =   array();         //if(!$ID){       print_r($location);       return       $location;}               
    if($ID){   
                                            $sql="select       *       from       $table_class       where       ID=$ID";   
            $result=mysql_query($sql)       or       die(mysql_error());   
                                            $row1       =       mysql_fetch_array($result);   
                                            $location[]=$row1["ID"]."".$row1["class_name"]."";           fuc_location($row1["parentID"]);       //   
                                } 
            return       $location;   }     
      

  8.   

     
    <?php
    function   fuc_location($ID,$location){
    global   $table_class;
    //if(!$ID){   print_r($location);   return   $location;}
    if($ID){
    $sql="select   *   from   $table_class   where   ID=$ID";
    $result=mysql_query($sql)   or   die(mysql_error());
    $row1   =   mysql_fetch_array($result);
    $location[]=$row1["ID"]."".$row1["class_name"]."";
    return fuc_location($row1["parentID"],$location);   //
    }else{
    return   $location;
    }
    }
    ?>