入门学习PHP之变量_1

1、函数里只能访问局部变量,不能访问全局变量,如果函数里需要访问全局变量则需要在变量前加global作用域,如下实例:

<?php
$x=5;
$y=10;
function myTest()
{
global $x,$y;
$y=$x+$y;
}
myTest();
echo $y; // 输出 15
?>
<?php
function myTest()
{
static $x=0;
echo $x;
$x++;
}
myTest();//0
myTest();//1
myTest();//2
?>
原文地址:https://www.cnblogs.com/hllive/p/5568098.html