Lokang 

PHP and MySQL

Comparison

In PHP, you can use comparison operators to compare two values and determine whether they are equal, greater than, or less than each other.

Here are the comparison operators available in PHP:

  • ==: Equal to
  • !=: Not equal to
  • >: Greater than
  • <: Less than
  • >=: Greater than or equal to
  • <=: Less than or equal to

These operators return a boolean value of true or false depending on the result of the comparison.

Example:

<?php
$x = 10;
$y = 20;
$result1 = $x == $y; // false
$result2 = $x != $y; // true
$result3 = $x > $y; // false
$result4 = $x < $y; // true
$result5 = $x >= $y; // false
$result6 = $x <= $y; // true
echo $result1 . "\n";
echo $result2 . "\n";
echo $result3 . "\n";
echo $result4 . "\n";
echo $result5 . "\n";
echo $result6 . "\n";
?>

You can also use the === operator to compare two values not only for equality, but also for their data types. This operator will return true only if both values are equal and of the same data type.

Example:

<?php
$x = 10;
$y = "10";
$result1 = $x == $y; // true
$result2 = $x === $y; // false
echo $result1 . "\n";
echo $result2 . "\n";
?>