Home Tutorial Php Phpbeginners Arithmetic Operators

 
 

Share on Google+Share on Google+
Arithmetic Operators
Posted on: February 4, 2011 at 12:00 AM
Advertisement
This section contains the detail about Arithmetic Operators in PHP.

Arithmetic Operators

Operator is used to perform operation on variable and values. Arithmetic Operators is used to perform arithmetic operations(like addition, subtraction, multiply divide etc )on variables and numeric.

Given below the list of available arithmetic operators :

OPERATOR WORK USE RESULT
+ Addition y=3
y+3
6
- Subtraction y=3
5-y
2
/ Division 21/3
7
% Modulus (division remainder) 10%8
 
2
++ Increment y=3
y++
4
* Multiplication y=3
y*3
9
-- Decrement y=5
y--
4

Some of the key notes are given below, which you should keep in mind before applying these arithmetic operator :

  • Unless two operands are not having type integer, the division operator( / )returns float. Also, if you are dividing  two numbers written as string then first it is converted to integer and then it perform division.

 

  • Operands are converted to integers (by stripping the decimal part) before processing.

 

  • If you are using % modular operator then the result of output or result will take the same sign as dividend(the left variable). For example :
<?php

echo (5 % 3)."\n";     // output  2
echo (5 % -3)."\n";    // output  2
echo (-5 % 3)."\n";    // output -2
echo (-5 % -3)."\n";   // output -2

?>

Advertisement

Related Tags for Arithmetic Operators:


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: February 4, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com