By now, you must have started writing those scripts and started working on PHP. Now, it’s time for you to learn about the operators available in PHP. An operator is something in which one or more values are fed and it gives another value as a result.

In general there are three types of operators:

**Unary** – it operates on only one value.
**Binary** – it operates on two or more than two values.
**Ternary** – it is used to select between two expressions depending on the third one.

There are many types of operators in PHP; some of them are useful but some are not. In this tutorial we will be studying about the most useful operators in PHP, which are:

**Arithmetic operators **
**Assignment operators **
**Comparison operators **
**Logical operators **

—————————————————————

**Arithmetic Operators**

**Addition (+)**

$a=20;

$b=10;

$c=$a+$b;

**Result** = 30

—————————————————————–

**Subtraction (-)**

$a=15;

$b=10;

$c=$a-$b;

**Result** = 5

—————————————————————

**Multiplication (*)**

$a=5;

$b=2;

$c=$a*$b;

**Result** = 10

—————————————————————

**Division (/)**

$a=30;

$b=2;

$c=$a/$b;

**Result** = 15

—————————————————————

**Modulus (%)**

$a=5;

$b=2;

$c=$a%$b;

**Result** = 1

—————————————————————

**Increment (++)**

$a=5;

$a++;

**Result** = 6

—————————————————————

**Decrement (–)**

$a=5;

$a–;

**Result** = 4

—————————————————————

**Assignment Operators**

**Equal to (=) **

$a=$b;

Is same as $a=$b;

—————————————————————

**Plus equal to ( += ) **

$a+=$b;

Is same as $a=$a+$b;

—————————————————————

**Minus equal to ( -= ) **

$a-=$b;

Is same as $a=$a-$b;

—————————————————————

**Multiply equal to ( *= ) **

$a*=$b;

Is same as $a=$a*$b;

—————————————————————

**Divide equal to ( /= ) **

$a/=$b;

Is same as $a=$a/$b;

—————————————————————

**Modulus equal to ( %= ) **

$a%=$b;

Is same as $a=$a%$b;

—————————————————————

**Comparison Operators **

**Equal to ( == ) **

3==5;

**Result:** False

—————————————————————

**Not equal to ( != ) **

3!=5;

**Result:** True

—————————————————————

**Greater than ( > ) **

3>5;

**Result:** False

—————————————————————

**Less than ( < ) **

3<5;

**Result:** True

—————————————————————

**Greater than or equal to (>=) **

3>=5;

**Result:** False

—————————————————————

**Less than or equal to (<=) **

3<=5;

Result: True

—————————————————————

**Logical Operators **

**And ( && ) **

$a=5;

$b=2;

($a>4 && $b<3);

**Result****:** True

—————————————————————

**Or (||) **

$a=7;

$b=8;

($a<5 || $b<5);

**Result:** False

—————————————————————

**Not (!) **

$a=5;

$b=5;

!($a==$b);

**Result:** False

—————————————————————

**source:**expertrating.com

to be continued

### Like this:

Like Loading...

*Related*

This entry was posted on July 31, 2008 at 11:06 pm and is filed under Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

August 20, 2008 at 12:14 pm |

Perhaps you wanna give an example of the underrated ternary operator.

It’s commonly ignored, while it shouldn’t.

Pretty pretty useful 😉

September 21, 2008 at 3:57 pm |

you can write this 😀 $result = $num<5 ? “num is greater than 5” : “num is less than 5”;

and I liked this blog guys , go on 😉