PHP Operators

Operators are used to perform some actions on variables and values. There are 7 types of operators.

1.PHP Arithmetic Operators

This operator is used with numerical values so that one can get value of a particular value.

Arithmetic operators are +, – , * , / , % , **(power)

Syntax:
Subtraction- \$a – \$b
Multiplication- \$a * \$b
Division- \$a / \$b
Modulus- \$a % \$b
Exponentiation- \$a ** \$b

Example: Use of PHP addition(+), subtraction(-), multiplication (*), division (/), modulo (%) and power(**) operators.

2. PHP Assignment Operators

It is used with numerical values when some need to write the value of a particular variable.

Assignment operators are =, +=, -=, *=,  /=, %=, **=

Syntax:

a = b a = b Left operand shifts to right operand
a += b a = a + b Addition
a -= b a = a – b Subtraction
a *= b a = a * b Multiplication
a /= b a = a / b Division
a %= b a = a % b Modulus

Example: Use of PHP Assignment Operators (=, +=, -=, *=, /=, %=, **=)

3. PHP Comparison Operators

== Equal
=== Identical
!= Not equal
<> Not equal
!== Not identical
> Greater than
< Less than >= Greater than or equal to
<= Less than or equal to

Example: Use of PHP equal (==) and  (===) Identical operators.

Example: Use of PHP (!=) Not equal and  (<>) Not equal  and (!==) Not identical operators.

Example: Use of PHP (>) Greater than, (<) Less than (>=) Greater than or equal to (<=) Less than or equal to operators.

4. PHP Increment or Decrement Operator

Increment decrement operators are ++ and –.

++\$x Pre-increment
\$x++ Post-increment
–\$x Pre-decrement
\$x– Post-decrement

Example: Use of PHP (++) pre-increment , post increment , (–) pre decrement and post decrement operators.

5. PHP Logical Operators

and, or ,xor, &&, ||, ! are logical operators in PHP

And \$x and \$y
Or \$x or \$y
Xor \$x xor \$y
And \$x && \$y
Or \$x || \$y
Not !\$x

Example: Use of PHP  (and , &&) and operator.

Result

Example: Use of PHP  (or , ||) and operator.

Example: Use of PHP  (!) not and (xor) xor operator.

6. PHP String Operators

. Concatenation \$txt1 . \$txt2
.= Concatenation assignment \$txt1 .= \$txt2

Example: Use of PHP  (.) Concatenation and and (.=) Concatenation assignment operator.

7. PHP Array Operators

It is used to compare arrays with each other

+ Union \$x + \$y
== Equality \$x == \$y
=== Identity \$x === \$y
!= Inequality \$x != \$y
<> Inequality \$x <> \$y
!== Non-identity \$x !== \$y

Example: Use of PHP  array  (+) union operator

`Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )`

Example: Use of PHP  array (==) Equality (===) Identity , (!=) Inequality (<>), Inequality and (!==) Non-identity and php (=>) operators.

Output