Assignment Operators (Chapter 5)

Main Lab 4 Page


Assigning values to variables is generally done with the assignment operator (=). However, there are other assignment operators that can edit variables in a more dynamic way.

Operator Action
= Replaces the variable on the left, with the value on the right.
+= Adds the value on the right, to the variable on the left.
-= Subtracts the value on the right, from the variable on the left.
.= Concatenates the value on the right, to the variable on the left.

These four assignment operators are demonstrated in the following block of PHP code:

Original value is 100

Added a value, now it's 125

Subtracted a value, now it's 113

Final answer: 113 chickens