PHP Operators: Relation Operators



PHP Operators Step By Step Tutorial - Part 6: Relation operator or which also referred as comparison operator is the operator that is used to conduct a comparison between two value or expression in order to get the result of true and false.

Table Relationship Operator

Operator Info example
== Equal to $x = 3;
$y = 4;
$x == $y
// the result : false or 0
True if $x is equal to $y
!=
or
<>
Unegual $x = 3;
$y = 4;
$x == $y
// the result : true or 1
True if $x is unegual than $y
=== Identik $x = 2;
$y = 2;
$x === $y
//the result : true or 1
True if $x is equal to $y as well as owning is the same type
!== Not Identik $x = 2;
$y = 5;
$x !== $y
//the result : false or 0
True if $x is not equal to $y or also both do not have is the same type
> Bigger $x = 2;
$y = 5;
$ x >$y
//the result : false or 0
True if $x is bigger than $y
< Smaller $x = 2;
$y = 5;
$ x <$y
//the result : true or 1
True if $x is smaller than $y
>= Bigger or equal to $x = 2;
$y = 5;
$ x >=$y
//the result : false or 0
True if $x is bigger or equal to $y
<= Smaller or equal to $x = 2;
$y = 5;
$ x <=$y
//the result : true or 1
True if $x is smaller or equal to $y

Pay attention to the example of using relationship operator at script as following:

File name: relationoperator.php

<html>
<head>
<title>Using Relation Operator</title>
</head>

<body>
<h1>The example for using relation operator</h1>
<?
$s = 100;
$a = 50;
$y = "310 pack";
$i = "me";
$o = "you";
printf ("$s == $a :%d <br>", $s==$a);
printf ("$s != $a :%d <br>", $s!=$a);
printf ("$s <> $a :%d <br>", $s<>$a);
printf ("$s === $y :%d <br>", $s===$y);
printf ("$s !== $y :%d <br>", $s!==$y);
printf ("$s > $a :%d <br>", $s > $a);
printf ("$i > $o :%d <br>", $i > $o);
printf ("$s < $a :%d <br>", $s < $a);
printf ("$i < $o :%d <br>", $i < $o);
printf ("$s >= $a :%d <br>", $s >= $a);
printf ("$i >= $o :%d <br>", $i >= $o);
printf ("$s <= $a :%d <br>", $s <= $a);
printf ("$i <= $o :%d <br>", $i <= $o);
?>
</body>
</html>
php relation operator


Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction


Tag: operator, Relation Operators Category: PHP Basic Post : March 08th 2008 Read: 1,571 Bookmark and Share

blog comments powered by Disqus