What is the & Ampersand Preceding Variables – reference – php &$

You may see PHP code snippets that have an ampersand, ‘&’, preceding a variable like &$examplevar.

So, what does it do? It sets up a reference to the original variable instead of copying it’s value.

Exemple:

$orig = “something 1″;

$reference = &$orig;

echo $reference  // will output “something 1″

Now if we change the $orig with something else

$orig = “something 2″;

echo $reference // will output “something 2″

Leave a comment

or Subscribe to this comment feed via RSS