PHP& $ string-这是什么意思? [英] PHP &$string - What does this mean?
问题描述
我一直在搜索,但找不到任何东西.
I've been googling but I can't find anything.
$x->func(&$string, $str1=false, $str2=false);
$string
&$string
之前的&
有什么作用?
what does that &
before $string
&$string
do?
推荐答案
您正在通过引用分配该数组值.
You are assigning that array value by reference.
通过引用(& $)传递参数,并通过$传递参数是,当您通过引用传递参数时,您将在原始变量上工作,这意味着如果您在函数内部对其进行更改,则也将在其外部进行更改.将参数作为副本传递,函数将创建此变量的副本实例,然后对该副本进行处理,因此,如果在函数中对其进行更改,则不会在其外部进行更改
passing argument through reference (&$) and by $ is that when you pass argument through reference you work on original variable, means if you change it inside your function it's going to be changed outside of it as well, if you pass argument as a copy, function creates copy instance of this variable, and work on this copy, so if you change it in the function it won't be changed outside of it
参考: http://www.php.net/manual/zh/language.references .pass.php
这篇关于PHP& $ string-这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!