Site icon TestingDocs.com

PHP Arithmetic Operators

Overview

In this tutorial, we will learn about PHP arithmetic operators. The arithmetic operators are as follows:

Table

Arithmetic

Operator

Operation Example Expression

Result

+ Addition 4 + 5 9
Subtraction 16 – 9 7
* Multiplication 12 * 3 36
/ Division 30 / 6 5
% Modulus 18 % 5 3

Example

Example PHP Program to show the operators in action.

<?php

// declare two variables a and b

$a = 11;
$b = 3;

//Perform operations

$sum = $a + $b;
$diff = $a – $b;
$product = $a * $b;
$div = $a / $b;
$mod = $a % $b;

//Output

echo “Addition is “.$sum;
echo “<br>”;
echo “Subtraction is “.$diff;
echo “<br>”;
echo “Multiplication is “.$product;
echo “<br>”;
echo “Division is “.$div;
echo “<br>”;
echo “Remainder is “.$mod;

?>

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Exit mobile version