August 2013
Intermediate to advanced
140 pages
1h 49m
English
CHAPTER 27
![]()
References
A reference is an alias which allows two different variables to write to the same value. There are three operations that can be performed with references: assign by reference, pass by reference and return by reference.
Assign by reference
A reference is assigned by placing an ampersand (&) before the variable that is to be bound.
$x = 5;$r = &$x; // r is a reference to x$s =& $x; // alternative syntax
The reference then becomes an alias for that variable and can be used exactly as if it was the original variable.
$r = 10; // assign value to $r/$xecho $x; // "10"
Pass by reference
In PHP, function arguments are by default ...
Read now
Unlock full access