Which of the below statements is equivalent to $a -= $b?
php
Which of the below statements is equivalent to $a -= $b?
An operators are symbols that tell the PHP processor to perform certain actions. To assign a value into a variable, assignment operator(=) is used. It assign the right side of expression or value (constant) to the variable on the left side of assignment operator. To do the arithmetic operations +, -, *, / and % arithmetic operator are used.
PHP also support some shorthand operators to do simultaneously arithmetic operation and assignment operation both. It is a short variant of assignment operator. They are: +=, -=, *=, /=, %= and .= (for string concatenate).
The symbol += is a addition-assignment operator, which add then assign the calculated value to the variable.
The symbol -= is a subtraction-assignment operator, which subtract then assign the calculated value to the variable.
The symbol *= is a multiplication-assignment operator, which multiply then assign the calculated value to the variable. etc.
Note: We can use the shorthand assignment operator if the variable of left side and right side of assignment operator must be same. i.e. $x=$x+5 then it can be written as $x +=5.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps