You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
543 B
24 lines
543 B
<?php
|
|
$a=1;
|
|
$b=2;
|
|
$c=3;
|
|
|
|
function func()
|
|
{
|
|
global $a,$b;
|
|
echo "a:$a"; //func内使用global引用了a和b,所以c没有打印出来
|
|
echo "<br> b:$b";
|
|
echo "<br> c:$c";
|
|
}
|
|
|
|
function func2()
|
|
{
|
|
echo "<br>a:".$GLOBALS['a']; // $GLOBALS['var'] 指的是函数外部变量本身,是一个变量.在程序的任意位置都能使用
|
|
echo "<br>b:".$GLOBALS['b'];
|
|
echo "<br>c:".$GLOBALS['c'];
|
|
}
|
|
|
|
func();
|
|
echo "<br>";
|
|
func2();
|
|
?>
|