The main assignment operator is ‘=’, which basically assigns a value on the right to a variable on the left. If you think this is the same as an equal sign in mathematics, don’t! Think of it as a ‘assigned to’ so whatever is on the right is assigned to the left.
Here’s a simple example:
// this example assigns the number 6 to the variable 'apples' $apples = 6;
There are a variety of ‘combined operators’ for all the binary arithmetic, array union and string operators that allows you to use a value in an expression and then assign its value to the result of that expression.
Here are the combined operators:
+= -= *= /= .= %= &= |= ^= <<= >>=
// Using *= assignment $a = 3; $a *= 6; //is the same as doing $a = $a * 6. $a will be 18. // Using .= assignment $b = 'Hello '; $b .= ' There!'; // is the same as doing $b = $b . 'There!';
The rest of the combined operators are used in the same way.