Arithmetic calculation operators in php

There are several operators in PHP available for arithmetic calculations and all.

Addition Operator : +
Use : For the addition of two numbers.
Example

<?php
$a = 30;
$b = 10;
$c = $a + $b;
echo $c;
?>

Output will be ( 30 + 10 ):
40

Subtraction Operator : –
Use : Subtract one value from another value
Example

<?php
$a = 30;
$b = 10;
$c = $a - $b;
echo $c;
?>

Output will be ( 30 – 10) :
20

Multiplication Operator : *
Use: Mutiply one value with another
Example

<?php
$a = 30;
$b = 10;
$c = $a * $b;
echo $c;
?>

Output will be ( 30 * 10) :
300

Division Operator : /
Use : for the division of one value by another
Example

<?php
$a = 30;
$b = 10;
$c = $a / $b;
echo $c;
?>

Output will be ( 30 / 10) :
3

Modulus Operator : %
It will return the division remainder
Example 1:

<?php
$a = 30;
$b = 10;
$c = $a % $b;
echo $c;
?>

Output will be remainder of 30 / 10 :
0

Example 2:

<?php
$a = 5;
$b = 2;
$c = $a % $b;
echo $c;
?>

Output will be remainder of 5 / 2) :
1

Example 3:

<?php
$a = 10;
$b = 4;
$c = $a % $b;
echo $c;
?>

Output will be the remainder of 10 / 4 :
2

Increment Operator : ++
Use: Its a short code for using against + 1
Example

<?php
$a = 30;
$a++;
echo $a;
?>

Output will be ( 30 + 1 ):
31

Decrement Operator : —
Use: Its a short code for using against – 1
Example

<?php
$a = 30;
$a--;
echo $a;
?>

Output will be ( 30 – 1 ):
29

Negation Operator : will return the opposite of number
Example

<?php
$a = 30;
$b = -$a;
echo $b;
?>

Output will be :
-30

Share
Share
Share