Press "Enter" to skip to content

phpArithmeticAssignment

PHP Arithmetic Assignment Operators

Operator NameOperator
Arithmetic Assignment Operators=

Example for PHP Arithmetic Assignment Operators

<?php
$num = 2;
$num += 2; // New value is 4
echo “New value is $num <br />”;
$num -= 1; // New value is 3
echo “New value is $num <br />”;
$num *= 4; // New value is 12
echo “New value is $num <br /> “;
$num /= 2; // New value is 6
echo “New value is $num <br />”;
$num %= 4; // New value is 2
echo “New value is $num<br />”;
?>