<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php.cn</title>
</head>
<body>
<?php
$x=5;
$y=6;
function test(){
global $x,$y;
$y=$x+$y;
}
test();
echo $y;
?>
</body>
</html>
执行以后结果为6,不应该是11吗,查看了下$x没有值
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你只是方法里使用了全局变量的值,全局变量的值并没有改变的
使用 $GLOBAL 超全局函数 打印下数据就知道数据在是多少了