PHP Arithmetic Operator


 

PHP Arithmetic Operator

In this PHP tutorial we will study about PHP Arithmetic Operator is is used to perform addition(+), subtraction(-), Division(/), Multiplication(*), modulus(%). with variable or value. PHP Arithmetic Operator Examples will make it more clear.

In this PHP tutorial we will study about PHP Arithmetic Operator is is used to perform addition(+), subtraction(-), Division(/), Multiplication(*), modulus(%). with variable or value. PHP Arithmetic Operator Examples will make it more clear.

Arithmetic Operators:

These are the most basic kind of operators. The PHP Arithmetic operator is used to perform addition(+), subtraction(-), Division(/), Multiplication(*), modulus(%). with variable or value. We all have done in our school days, and some of us have practiced in different languages, syntax is almost same as other languages. Different examples will try to make it clear:

Example (Unary Operator):

<?php

$a=-12;

echo $a."<br/>";

$a=-$a;

echo $a."<br/>";

$a++;

echo $a."<br/>";

echo $a--."<br/>";

echo --$a."<br/>";

?>

Output:

-12
12
13
13
11

Example (Binary operator):

<?php

$a=-12+34-45/5*4;

echo $a;

?>

Output:

-14

Example (Binary operator):

<?php

$a=12;

echo $a/6 ."<br/>";

echo $a%5 ."<br/>";

echo $a*3 ."<br/>";

echo 5+5 ."<br/>";

echo 4-4 ."<br/>";

0

?>

Output:

2
2
36
10
0

1

Ads