PHP Operators

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

1.Arithmetic Operator

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

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

2. Assignment Operator

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

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

3.Comparison Operator

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

4.Increment or Decrement Operator

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

5. Logical

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

6. String Operator

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

7. Array

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

Leave a Reply

Your email address will not be published.