復制代碼 代碼如下:
$test = 123;
abc(); //這里什么都不輸出,因為訪問不到$test變量
function abc(){
echo($test);
}$test = 123;
abc(); //這里什么都不輸出,因為訪問不到$test變量
function abc(){
echo($test);
}
復制代碼 代碼如下:
$test = 123;
abc(); //輸出123
function abc(){
global $test;
echo($test);
}$test = 123;
abc(); //輸出123
function abc(){
global $test;
echo($test);
}
復制代碼 代碼如下:
function abc(){
global $test;
$test = 123;
}
abc();
echo($test); //輸出123function abc(){
global $test;
$test = 123;
}
abc();
echo($test);
復制代碼 代碼如下:
<?php
function Test_Global()
{
Test();
}
include 'B.php'; //將include 從局部Test_Global函數中移出
$a = 0 ;
Test_Global();
echo $a;
?>
//B.php 文件
<?php
function Test()
{
global $a;
$a =1;
}
?>
復制代碼 代碼如下:
//A.php 文件
<?php
include 'B.php';
$a =0;
Set_Global($a);
echo $a;
?>
//B.php 文件
<?php
function Set_Global(&$var)
{
$var=1;
}
?>
新聞熱點
疑難解答