Home Tutorial Php Phpbasics Tutorial PHP Arithmetic Operator

 
 

PHP Arithmetic Operator
Posted on: March 19, 2010 at 12:00 AM
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

Advertisement

Related Tags for PHP Arithmetic Operator:


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.

Posted on: March 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com