By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP Assignment Operators

Reference on PHP Assignment Operators. Assignment by value, and Assignment by Reference.

Edited: 2015-12-04 10:33

The basic Assignment Operator is the equal sign "=", in practice it translates to "gets set to".

I.e. $Whatever "gets set to" X;

Note. You should also check out the PHP Operators Reference, for a complete list of Operators.

Assignment by value

Here are some examples using the equal sign.

$Whatever = "Brugbart is";
$Whatever .= "cool"; // Sets $Whatever to "Brugbart is cool".

$Whatever = 4;
$Whatever += 4; // Sets $Whatever to "8", (Cough. The number of letters in Brugbart)

Assignment by Reference

Its also possible to assign values by reference, as demonstrated below.

$Main = "Cool Stuff";
$Reference = &$Main; // "$Reference" is just a reference to "$Main"

echo $Reference; // outputs "Cool Stuff" 

Changing the value of $Main, would also change the output of $Reference.