 Comparison Operators
× Gray Matter
Comparison Operators

## Comparison Operator

Comparison operator is used to compare string, integer and floats. Below are some examples.

### Operator (==)

This operator check if the value of two operands are equal. The condition true only if operands are equal.

``````<?php
\$x = 6;
\$y = "6";
\$z = 7;
var_dump(\$x == \$y); // It will return true because values are equal
var_dump(\$x == \$z); // It will return false because values are not equal
?> ``````

Output:

boolean true

boolean false

### Operator (===)

This operator check whether the value of two operands are equal and type is same. It will return true value only if both condition will be true.

See below example-

``````<?php
\$x = 6;
\$y = "6";
var_dump(\$x === \$y); // It will return false because type are not same
?> ``````

Output:

boolean false

### Operator (!= OR <>)

This operator returns true if the value of operands are not equal.

See below example-

``````<?php
\$x = 6;
\$y = "6";
var_dump(\$x != \$y); // It will return false because values are equal
var_dump(\$x <> \$y); // It will return false because values are equal
?>``````

Output:

boolean false

### Operator (!==)

This operator returns true value only if value of both operands are not equal or both are of different type.

See below example-

``````<?php
\$x = 6;
\$y = "6";
var_dump(\$x !== \$y); // It will return true because types are not equal
?>``````

Output:

boolean true

### Operator (> and <)

Operator (>) returns true if value of left side operand is greator then the value of right side operand. And operator (<) returns true if value of left side operand is less then the value of right side operand. Likely (==) and (!=), these operators are just opposit of each other.

See below example-

``````<?php
\$x = 6;
\$y = 7;
var_dump(\$x > \$y); // It will return false because \$x is less then \$y
var_dump(\$x < \$y); // It will return true because \$x is less then \$y
?>
``````

Output:

boolean false

boolean true

### Operator (<= and >=)

Operator (<=) returns true if the value of left side operand is less then or equal the value of right side operand. And the operator (>=) is just opposit of it.

See below code-

``````<?php
\$x = 6;
\$y = 7;
var_dump(\$x <= \$y); // It will return true because \$x is less than \$y
var_dump(\$x >= \$y); // It will return false because \$x is less than \$y
?>``````

Output:

boolean true

boolean false

We can do much more with comparison operators. Visit CodeLAB to prectice with your own code.

← Preview

Assignment Operators

Next →

Logical Operators

NOTES Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

## Courses

• Python
• Game Development with Unity 3D
• Arduino
• PCB & Circuit Designing
• Robotics and Embedded C
• 8051/8052 Embedded Systems Get the Android App Get the iOS App