What does this mean?
This question already has an answer here:
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
Ref: http://www.php.net/manual/en/language.references.pass.php
The & states that a reference to the variable should be passed into the function rather than a clone of it.
In this situation, if the function changes the value of the parameter, then the value of the variable passed in will also change.
However, you should bear in mind the following for PHP 5:
You can find more information here: http://www.php.net/manual/en/language.references.pass.php
And there's a lot of information here: Reference - What does this symbol mean in PHP?
An example of the behaviours of strings:
function changeString( &$sTest1, $sTest2, $sTest3 ) {
$sTest1 = 'changed';
$sTest2 = 'changed';
$sTest3 = 'changed';
}
$sOuterTest1 = 'original';
$sOuterTest2 = 'original';
$sOuterTest3 = 'original';
changeString( $sOuterTest1, $sOuterTest2, &$sOuterTest3 );
echo( "sOuterTest1 is $sOuterTest1rn" );
echo( "sOuterTest2 is $sOuterTest2rn" );
echo( "sOuterTest3 is $sOuterTest3rn" );
Outputs:
C:test>php test.php
PHP Deprecated: Call-time pass-by-reference has been deprecated; If you would l
ike to pass it by reference, modify the declaration of changeString(). If you w
ould like to enable call-time pass-by-reference, you can set allow_call_time_pas
s_reference to true in your INI file in C:testtest.php on line 13
Deprecated: Call-time pass-by-reference has been deprecated; If you would like t
o pass it by reference, modify the declaration of changeString(). If you would
like to enable call-time pass-by-reference, you can set allow_call_time_pass_ref
erence to true in your INI file in C:testtest.php on line 13
sOuterTest1 is changed
sOuterTest2 is original
sOuterTest3 is changed
& = Passing by reference:
References allow two variables to refer to the same content. In other words, a variable points to its content (rather than becoming that content). Passing by reference allows two variables to point to the same content under different names. The ampersand ( & ) is placed before the variable to be referenced.
链接地址: http://www.djcxy.com/p/10096.html上一篇: PHP中的or运算符的行为
下一篇: 这是什么意思?