global全局变量

global1.php

<?php 

//http://baike.baidu.com/link?url=MkrIj703CIMZt8Gw5P1Cb0yLS4dVNcuLiKU-tUohmDvHLy-h7ITlSSx5UqTwmZTG24vf13_LppPaKNFzpq1Bea
$x = 75; 
$y = 25;
 
function addition() 

$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y']; 
}
addition(); 
echo $z; 
?>

global2.php

<?php
//http://zhidao.baidu.com/link?url=_lORJbc-tPYwiSu7LYM1m52cW2FwgLKEhs2Dw1yOlQ7L8NZbbNIBtD5BEV4QUjj8pZxhg86FZN87mK5iDcFFnq
$var = 100;
echo "var=>".$var;
function fun1(){
  echo($var);
}
fun1();
function fun2(){
  global $var;
  echo("var=>".$var);
}
fun2();
?>

global3.php

<?php  
//http://happyqyt10.blog.163.com/blog/static/3002347620103215515309/
// 例子1  
function test_global() {  
  global $var1, $var2;  
  $var2 =& $var1;  
}  
function test_globals() {  
  $GLOBALS['var3'] =& $GLOBALS['var1'];  
}  
$var1 = 5;  
$var2 = $var3 = 0;  
test_global();  
print $var2 ."\n";  
test_globals();  
print $var3 ."\n";  
?> 

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

发表评论

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