php拥有四种作用域,但是常用的只有一两种:
global,该作用域主要是用来在函数内访问全局变量
<?php
$x=5;
$y=6;
function MyTest(){
global $x $y;
$y=$x+$y;
}
MyTest();
echo $y;//输出为15
?>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号