什么是使用&在函数的参数之前? [英] What's the purpose of using & before a function's argument?
本文介绍了什么是使用&在函数的参数之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
函数boo(& $ var){
.. 。
}
&
character do?
解决方案
这是一个引用传递。
函数foo(& $)函数指向与调用上下文中的变量相同的数据。 bar)
{
$ bar = 1;
}
$ x = 0;
foo($ x);
echo $ x; // 1
I saw some function declarations like this:
function boo(&$var){
...
}
what does the &
character do?
解决方案
It's a pass by reference. The variable inside the function "points" to the same data as the variable from the calling context.
function foo(&$bar)
{
$bar = 1;
}
$x = 0;
foo($x);
echo $x; // 1
这篇关于什么是使用&在函数的参数之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文