Arithmetic operators are used to perform common mathematical operations on variables and values in PHP.
+ Addition- Subtraction* Multiplication/ Division% Modulus (remainder)** Exponentiation (power)PHP arithmetic operators work on numeric operands. You can combine multiple operators in one expression, and PHP follows standard mathematical precedence rules.
Test how variables $a and $b interact!
// Demonstrating all PHP arithmetic operators
<?php
$a = 10;
$b = 3;
echo "Addition: " . ($a + $b) . "<br>";
echo "Subtraction: " . ($a - $b) . "<br>";
echo "Multiplication: " . ($a * $b) . "<br>";
echo "Division: " . ($a / $b) . "<br>";
echo "Modulus: " . ($a % $b) . "<br>";
echo "Exponentiation: " . ($a ** $b);
?>
The script performs arithmetic operations on two numbers ($a = 10 and $b = 3) and prints each result using echo.
Change the values of $a and $b and refresh the page to instantly see how different numbers affect each operation.
() to improve readability and ensure correct calculation.** is available from PHP 5.6 onward.arithmetic.php.echo.