函数作用域
function
func1.php
<?php
function func(){
$var=2;
echo "var=>".$var."<br>";
}
$var=1;
echo "var=>".$var."<br>";
func();
echo "var=>".$var."<br>";
?>
func2.php
<?php
function func(){
$GLOBALS["var"]=2;
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
}
$var=1;
echo "var=>".$var."<br>";
func();
echo "var=>".$var."<br>";
?>
func3.php
<?php
function func(){
global $var;
$var=2;
echo "var=>".$var."<br>";
}
$var=1;
echo "var=>".$var."<br>";
func();
echo "var=>".$var."<br>";
?>