Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

PHP Operators with example

Operator in PHP is a symbol that is used to perform operations.For example: +, -, *, / etc.

There are many types of operators in PHP which are given below:

  1. Arithmetic operators
  2. Assignment operators
  3. Comparison operators
  4. Increment/Decrement operators
  5. Logical operators
  6. String operators
  7. Array operators

Arithmetic operators

Operator Description Example Result Run It
+ Addition $x + $y Sum of $x and $y Run It »
- Subtraction $x - $y Difference of $x and $y. Run It »
* Multiplication $x * $y Product of $x and $y. Run It »
/ Division $x / $y Quotient of $x and $y Run It »
% Modulus $x % $y Remainder of $x divided by $y Run It »

Assignment operators

Operator Description Example Is The Same As Run It
= Assign $x = $y $x = $y Run It »
+= Add and assign $x += $y $x = $x + $y Run It »
-= Subtract and assign $x -= $y $x = $x - $y Run It »
*= Multiply and assign $x *= $y $x = $x * $y Run It »
/= Divide and assign quotient $x /= $y $x = $x / $y Run It »
%= Divide and assign modulus $x %= $y $x = $x % $y Run It »

Comparison operators

Operator Name Example Result Run It
== Equal $x == $y True if $x is equal to $y Run It »
=== Identical $x === $y True if $x is equal to $y, and they are of the same type Run It »
!= Not equal $x != $y True if $x is not equal to $y Run It »
<> Not equal $x <> $y True if $x is not equal to $y Run It »
!== Not identical $x !== $y True if $x is not equal to $y, or they are not of the same type Run It »
< Less than $x < $y True if $x is less than $y Run It »
> Greater than $x > $y True if $x is greater than $y Run It »
>= Greater than or equal to $x >= $y True if $x is greater than or equal to $y Run It »
<= Less than or equal to $x <= $y True if $x is less than or equal to $y Run It »

Increment/Decrement operators

Operator Name Effect Run It
++$x Pre-increment Increments $x by one, then returns $x Run It »
$x++ Post-increment Returns $x, then increments $x by one Run It »
--$x Pre-decrement Decrements $x by one, then returns $x Run It »
$x-- Post-decrement Returns $x, then decrements $x by one Run It »

Logical operators

Operator Name Example Result Run It
and And $x and $y True if both $x and $y are true Run It »
or Or $x or $y True if either $x or $y is true Run It »
xor Xor $x xor $y True if either $x or $y is true, but not both Run It »
&& And $x && $y True if both $x and $y are true Run It »
|| Or $x || $y True if either $$x or $y is true Run It »
! Not !$x True if $x is not true Run It »

String operators

Operator Description Example Result Run It
. Concatenation $str1 . $str2 Concatenation of $str1 and $str2 Run It »
.= Concatenation assignment $str1 .= $str2 Appends the $str2 to the $str1 Run It »

Array Operator

Operator Name Example Result Run It
+ Union $x + $y Union of $x and $y Run It »
== Equality $x == $y True if $x and $y have the same key/value pairs Run It »
=== Identity $x === $y True if $x and $y have the same key/value pairs in the same order and of the same types Run It »
!= Inequality $x != $y True if $x is not equal to $y Run It »
<> Inequality $x <> $y True if $x is not equal to $y Run It »
!== Non-identity $x !== $y True if $x is not identical to $y Run It »