By-Reference Assignment Operator

chinmay.sahoo

New member
PHP enables you to create variables as aliases for other variables. You can achieve this by using the by-reference assignment operator =&. After a variable aliases another variable, changes to either one of them affects the other.


For example:

$name = "Judy";
$name_alias =& $name;
$name_alias = "Jonathan";
print $name;

The result of this example is



When returning a variable by-reference from a function (covered later in this book), you also need to use the assign by-reference operator to assign the returned variable to a variable:

$retval =& func_that_returns_by_reference();
 
Back
Top