Share on Google+Share on Google+

PHP Arithmetic Operator

Advertisement
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/>";

?>

Output:

2
2
36
10
0

Advertisements

Advertisement

Posted on: March 19, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.