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”

What is the & Ampersand Preceding Variables – reference – php &$
1 (20%) 2 votes

Leave a Reply

Your email address will not be published. Required fields are marked *