Arithmetic Operators in PHP

phpLike any other programming language, we do have integer and float data types in PHP.  Integers are whole numbers, can have both positive and negative values like -1, -2, 1, 3 etc.  Floats are known as decimal numbers like 1.25, 3.2 etc.  Using integers and floats, we can perform numerical calculations like addition, subtraction, division etc.  To do so, we make use of arithmetic operators such as:

  • Addition (+)
  • Subtraction ()
  • Multiplication (*)
  • Division (/)
  • Modulus (%)

Example is given below for all the above listed arithmetic operators.

<?php

$n1 = 50;
$n2 = 10;

echo 'Addition: '. ($n1+$n2) .'<br />';
echo 'Substraction: '. ($n1-$n2) .'<br />';
echo 'Multiplication: '. ($n1*$n2) .'<br />';
echo 'Division: '. ($n1/$n2) .'<br />';
echo 'Modulus: '. ($n1%$n2) .'<br />';

?>