无全局变量,怎么获取父function中的变量$a?
<?php
function hello(){
$a="1111";
function test(){
$b=$a; //怎么获取父function中的变量$a?
echo $b;
}
test();
}
hello();
?>

解决方案 »

  1.   


    function hello(){
         global $a;
         $a="1111";
         function test(){
              global $a;
              $b=$a;    //怎么获取父function中的变量$a?
                echo $b;
         }
        test();
    }
      hello();
      

  2.   

    function   hello(){ 
              global  $a;   //定义$a 为全局变量
              $a= "1111 "; 
              function   test(){ 
                      global  $a; //引用函数外部$a的全局变量
                      $b=$a;       
                         echo $b; 
              } 
            test(); 

        hello(); 
      

  3.   


    function hello(){
    global $a;
    $a="1111";
    function test(){
    global $a;
    $b=$a;    //怎么获取父function中的变量$a?
    echo $b;
    }
    test();
    }
    hello();
      

  4.   

    不用global就只有当参数传过去了