这个问题在这里已经有了答案:
Reference — What does this symbol mean in PHP?
(23 个回答)
7年前关闭。
是什么意思"&" 中的平均值'&$var' 在 PHP ?有人可以帮助我进一步解释这一点。先感谢您。
最佳答案
这意味着通过 reference 传递变量,而不是传递变量的值。这意味着当程序流返回调用代码时,对 preparse_tags 函数中该参数的任何更改都会保留。
function passByReference(&$test) {
$test = "Changed!";
}
function passByValue($test) {
$test = "a change here will not affect the original variable";
}
$test = 'Unchanged';
echo $test . PHP_EOL;
passByValue($test);
echo $test . PHP_EOL;
passByReference($test);
echo $test . PHP_EOL;
输出:
Unchanged
Unchanged
Changed!
关于php - PHP中的 "&"中的 '&$var'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604666/