# PHP - Operators

A full list of PHP operators follows in the section Operator Precedence. The section also explains operator precedence and associativity, which govern exactly how expressions containing several different operators are evaluated.php operators can be classified info the following three categories:

### Unary Operators

1. Negation Operators

2. Increment & Decrement Operators

3. Cast Operators

### Binary Operators

1. Arithmetic Operators

2. Assignment Operators

3. Concatenation Operators

4. Comparison Operators

5. Logical Operators

6. Bitwise Operators

### Ternary Operators

1. Condition Operators

## Unary Operators

As unary operations have only one operand they are evaluated before other operations containing them in php,here is an example and list of unary operators in php using negation.

Operators

Meaning

Example

Result

!

Logical Negation

\$x=2,!(\$x==2)

True

~

Bitwise Negation

\$x=2,\$y=~\$x

\$y=-3

Operators

Meaning

Example

Result

\$x++

Post Increment

\$x=2,\$y=\$x++

\$x=3,\$y=2

++\$x

Pre Increment

\$x=2,\$y=++\$x

\$x=3,\$y=3

\$x--

Post Decrement

\$x=2,\$y=\$x--

\$x=1,\$y=2

--\$x

Pre Decrement

\$x=2,\$y=--\$x

\$x=1,\$y=1

Operators

Meaning

Example

Result

int

Integer

\$n=(int)12.24

\$n=12

## Binary Operators

In php,a binary operation on a set is a calculation that combines two elements of the set (called operands) to produce another element of the set (more formally, an operation whose arity is two, and whose two domains and one codomain are (subsets of) the same set). Examples include the familiar elementary arithmetic operations of addition, subtraction, multiplication and division.

### Arithmetic Operators

Operators

Meaning

Example

Result

+

\$x=2,\$y=2 - \$x+\$2

4

-

Subtraction

\$x=2,\$y=2 - \$x-\$2

0

*

Multiplication

\$x=2,\$y=2 - \$x*\$2

4

/

Division

\$x=2,\$y=2 - \$x/\$2

1

%

Modulus

\$x=2,\$y=2 - \$x%\$2

0

### Assignment Operators

Operators

Meaning

Example

Result

=

Equals to

\$y=2,\$x=\$y

\$x=2

+=

Plus Equals to

\$x=10,\$y=2 - \$x+=\$y

\$x=12

-=

Minus Equals to

\$x=10,\$y=2 - \$x-=\$y

\$x=8

*=

Multiply Equals to

\$x=10,\$y=2 - \$x*=\$y

\$x=20

/=

Divide Equals to

\$x=10,\$y=2 - \$x/=\$y

5

.=

Dot Equals to

\$x=10,\$y=2 - \$x.=\$y

\$x=102

%=

Modulus Equals to

\$x=10,\$y=2 - \$x%=\$y

0

### Concatenation Operators

Operators

Meaning

Example

Result

.(Dot)

Concatenation

"tutorials"."studio"

tutorialsstudio

### Comparison Operators

Operators

Meaning

Example

Result

==

Is Equals to

\$x=1,\$y=2 - \$x==\$y

False

!=

Is not Equals to

\$x=1,\$y=2 - \$x!=\$y

True

<

Is Less Than

\$x=2,\$y=1 - \$x<\$y

False

<=

Less Than or Equals to

\$x=2,\$y=2 - \$x<=\$y

True

>

Is Greater Than

\$x=1,\$y=2 - \$x>\$y

False

>=

Is Greater Than or Equals to

\$x=2,\$y=2 - \$x>=\$y

True

===

Is Identical to

\$x=1,\$y="1" - \$x===\$y

False

!==

Is Not Identical to

\$x=1,\$y="1" - \$x!==\$y

True

### Logical Operators

Operators

Meaning

Example

Result

&&,and

And

\$x=15,\$\$y=10,\$z=20 - \$x>\$y and \$x<\$z

True

||,or

Or

\$x=5,\$y=10,\$z=20 - \$x>\$y or \$x<\$z

True

### Bitwise Operators

Operators

Meaning

Example

Result

&

Bitwise AND

\$x=12,\$y=9 - \$z=\$x & \$y

\$z=8

|

Bitwise OR

\$x=12,\$y=9 - \$z=\$x | \$y

\$z=13

^

Bitwise XOR

\$x=12,\$y=9 - \$z=\$x ^ \$y

\$Z=5

<<

Bitwise Shift Left

\$x=12,\$y=9 - \$z=\$x << \$y

\$z=48

>>

Bitwise Shift Right

\$x=12,\$y=2 - \$z=\$x >> \$y

\$z=3

## Ternary Operators

In php, ?: is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages. It is commonly referred to as the conditional operator, inline if (iif), or ternary if.

### Condition (?)

Operators

Meaning

Example

Result

?True:False

Ternary Conditional

\$x=15 \$a=(\$x<=10)?"x is<=10":"x is >=10"

x is > 15