O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 27

image

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required