PHP Tutorials 6: PHP Operators 2

Previously we have learnt about some of the PHP Operators, this article is continuance of the article “PHP Tutorials 5: PHP Operator“.

PHP Operators:

Increment/Decrement Operators:

This operators are used to increment or decrement variables’ values. Concentrate on the example below with the description inside:

Most of the strict type programming languages are having two types of increment or decrement:

  • Post-Increment / Decrement
  • Pre-Increment /Decrement

As above Post-increment/decrement and Pre-Increment/Decrement both are Operators and add or subtract variables’ values but there are some situations based differences between these two types (Post and Pre). Look at the example below and the description:

Operator Name Description
++$x Pre-Increment Increments $x by one, then returns $x
$x++ Post-Increment Returns $x, then increments $x by one
–$x Pre-Decrement Decrements $x by one, then returns $x
$x– Post-Decrement Returns $x, then decrements $x by one

Comparison Operators:

these operators are used to compare two values of the same data type (number / string). Comparison operators response with True or False after comparison.

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

String, Array and Logical Operators will be discussed in the next tutorial. be with and learn the way to code!


  • Leave a Reply

    %d bloggers like this: