References

Using the equal sign (=) copies the value from one variable to another so they both have their own copy of the value. Another option here is to use references, which is where a variable does not have a value of its own; instead, it points to another variable. This enables you to share values and have variables mutually update themselves.

To copy by reference, use the & symbol, as follows:

<?php  $a = 10;  $b = &$a;  echo $a . "\n";  echo $b . "\n";  $a = 20;  echo $a . "\n";  echo $b . "\n";  $b = 30;  echo $a . "\n";  echo $b . "\n";?>

If you run that script, you will see that updating $a also updates $b, but also that updating $b updates $a.

Get Ubuntu Unleashed 2014 Edition: Covering 13.10 and 14.04,Ninth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.