PHP Assignment Operators
PHP Assignment operators in PHP are used to create and initialize a variable. The most basic assignment operator is the (=) sign, which you can use to assign and update the value of variables.
The lefthand side of a variable is always variable, and the right hand can be literal, complex expression, simple variable or function. Assignment operators supported by PHP are Assign(=),Add then assign(+=),Subtract then assign(-=),Multiply then assign(*),divide then assign(/=).
Operator | Name | Example | Explanation |
---|---|---|---|
= | Assign | $m = $n | The value of $n is assigned to $n |
+= | Add and Assign | $m += $n | It works similar to $m = $m + $n |
-= | Subtract and Assign | $m -= $n | Subtraction similar to $m = $m - $n |
*= | Multiply and Assign | $m *= $n | Multiplication similar to $m = $m * $n |
/= | Divide and Assign (quotient) |
$m /= $n | Find quotient similar to $m = $m / $n |
%= | Divide and Assign (remainder) |
$m %= $n | Find remainder similar to $m = $m % $n |
PHP - Assign Operator(=):-
Output:
PHP - Add and assign Operator(+=):-
Output:
PHP - Subtract and assign Operator(-=):-
Output:
PHP - Multiply and assign Operator(*=):-
Output:
PHP - Divide and assign Operator(/=):-
Output: