Friday 25 November 2011

PHP Operator


The symbol which are used to perform mathematical or logical operation are known as operator.

In php there are different type of operator available which are given below.

·         Arithmetic operator
·         Relational operator
·         Logical operator
·         Assignment operator

1. Arithmetic operator

Arithmetic operator are used when any mathematical operation is to be done. There are different operators of arithmetic as given below.

Operator
Description
Example
Result
+
Used for addition
x=2,y=2    x+y
4
-
Used for subtraction
x=2,y=2    x-y
0
*
Used for multiplication
X=2,y=2    x*y
4
/
Used for division
X=2,y=2    x/y
1
%
Used for modules
X=2,y=2    x%y
0
++
Used for increment
X=2           x++
3
--
Used for decrement
X=2           x--
1

2. Relational/Comparison operator

When the variables are related to some value at that time the relational operator is used. There are different relational operators used as below.

Operator
Description
==
This operator is used to compare the two variables or the value to check the equality. It checks only the value and not the data type. So even if the data types are different for the two variables it will return “true” if they have same value.
===
This operator is also used for comparing the equality of the variables or the values to check the equality. It will check not only the value but the data types are also checked. It will return true only if the values and data types are equal.
!=
This operator is for not equality. It will return true if the values are not equal regardless the data.
!==
This operator is for not quality but different from above. It will return true if the values are not equal and if the data types are not same.
< 
Used for less than.
>
Used for greater than
>=
Used for greater than equal to
<=
Used for less than equal to

3. Logical operator

When more than two conditions are to be checked at the same time, then logical operator can be helpful. There are different logical operators as given below.

Operator
Description
&&
And operator. Returns true if all the condition are true.
||
Or operator. Returns true if any of the condition is true.
!
Not operator. It reverses the condition. That means if the result of the condition is true then it converts it into false and vice versa.

4.     Assignment operator

There are different assignment operators as given below.

Operator
Description
=
Assigning the value x=y
*=
X*=y is similar to x=x*y
/=
X/=y is similar to x=x/y
+=
X+=y is similar to x=x+y
-=
X-=y is similar to x=x-y
%=
X%=y is similar to x=x%y



Posted By : Hemangi Zala

No comments:

Post a Comment