Account
Categories

Subtraction Assignment Operator(-=)


The -= sign is called the Subtraction Assignment Operator.

It takes the value on the left, subtracts the value on the right, and saves the result in the same variable.

The value on the right side is being input into the variable on the left side.

Syntax:
$variable -= value;
Example:
<?php
$x = 15;
$x -= 5; // subtracts 5 from $x, now $x is 10
?>

By the graphical representation:

old value->[15]         new value->[5] 
variable ->  a               a                     
               
                 |           |
                    subtract
                       |
                    15 - 5 = 10
                       |
 The final result  assigned in -> a = 10
Output:
10