function作用域

函数作用域

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>";
?>

    A+
发布日期:2014年07月10日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: