In this tutorial, you shall learn about Addition Assignment Operator, its syntax, and how to use this operator in programs, with examples.
PHP – Addition Assignment Operator
Addition assignment operator is used to increase the value in a variable by given value.
The operator takes two operands, and assigns the sum of both the operands to the first operand.
Syntax
The syntax of using Addition Assignment Operator is
operand1 += operand2
The operation would be similar to the following statement.
operand1 = operand1 + operand2
which translates to the meaning of increasing or incrementing 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 Addition Assignment Operator to increase the value in variable $x
by 10
.
PHP Program
<?php
$x = 41;
$x += 10;
print_r("Now, x is {$x}.");
?>
Output
Conclusion
In this PHP Tutorial, we learned about Addition Assignment Operator, and how to use it to increase a variable by given value.