1 <?php 
 2    $test = "test";
 3    function show1($abc){//直接把参数传入函数,函数能用
 4        echo $abc.'<br>';
 5    }
 6    
 7    function show2(){//不给函数传参数,所以使用不了外部变量,报错
 8        echo $test.'<br>';
 9    }
10    
11    function show3(){//可以通过$GLOBALS来调用外部变量
12        echo $GLOBALS['test'].'<br>';
13    }
14    echo "it is show1 function<br>";
15    show1($test);
16    echo "it is show2 function<br>";
17    show2();
18    echo "it is show3 function<br>";
19    show3();
20    
21 ?>
View Code

相关文章: