Assignment operators
Assignment operators in PHP are used to assign values to variables. They allow you to perform an operation and then assign the result to a variable in one step. Here are the assignment operators supported in PHP:
Assignment (=)
Assigns the value of the right operand to the left operand.
$x = 5; // Assigns the value 5 to the variable $x
Addition assignment (+=)
Adds the value of the right operand to the variable on the left and assigns the result to the left operand.
$x += 3; // Equivalent to: $x = $x + 3
Subtraction assignment (-=)
Subtracts the value of the right operand from the variable on the left and assigns the result to the left operand.
$y -= 2; // Equivalent to: $y = $y - 2
Multiplication assignment (*=)
Multiplies the value of the right operand with the variable on the left and assigns the result to the left operand.
$z *= 4; // Equivalent to: $z = $z * 4
Division assignment (/=)
Divides the value of the variable on the left by the value of the right operand and assigns the result to the left operand.
$a /= 2; // Equivalent to: $a = $a / 2
Modulus assignment (%=)
Performs the modulus operation on the variable on the left with the value of the right operand and assigns the result to the left operand.
$b %= 3; // Equivalent to: $b = $b % 3