In this tutorial, you shall learn about Subtraction Assignment Operator, its syntax, and how to use this operator in programs, with examples.

PHP – Subtraction Assignment Operator

Subtraction assignment operator is used to decrease the value in a variable by given value.

The operator takes two operands, and assigns the difference of second operand from the first operand back to the first operand.

Syntax

The syntax of using Subtraction Assignment Operator is

</>
Copy
operand1 -= operand2

The operation would be similar to the following statement.

</>
Copy
operand1 = operand1 - operand2

which translates to the meaning of decreasing or decrementing the value of operand1 by the value of operand2.

We can use variable for operand1; variable or value for operand2.

Example

In the following example, we use Subtraction Assignment Operator to decrease the value in variable $x by 10.

PHP Program

</>
Copy
<?php
$x = 41;
$x -= 10;
print_r("After subtraction assignment, x is {$x}.");
?>

Output

PHP - Subtraction Assignment Operator

Conclusion

In this PHP Tutorial, we learned about Subtraction Assignment Operator, and how to use it to decrease a variable by given value.