Possible Duplicate:
Reference - What does this symbol mean in PHP?
Can anyone explain this experssion
&variablename in PHP.
I have seen this around at many places but i am not able to figure out what does this statement do.
Thanks in advance
J
Possible Duplicate:
Reference - What does this symbol mean in PHP?
Can anyone explain this experssion
&variablename in PHP.
I have seen this around at many places but i am not able to figure out what does this statement do.
Thanks in advance
J
PHP reference. References in PHP are a means to access the same variable content by different names. There are three operations performed using references: assigning by reference, passing by reference, and returning by reference.
for example:
$example1 = 'something';
$example2 =& $example1;
echo("example 1: $example1 | example 2: $example2\n"); //example 1: something | example 2: something
$example1 = 'nothing'; //change example 1 to nothing
echo("example 1: $example1 | example 2: $example2"); //example 1: nothing | example 2: nothing
You can pass variable to function by reference, so that function could modify its arguments. The syntax is as follows:
<?php
function foo(&$var)
{
$var++;
}
$a=5;
foo($a);
// $a is 6 here
?>
taken from http://www.phpbuilder.com/manual/language.references.pass.php