Saturday, November 22, 2025
HomeLanguagesDifference between $a != $b and $a !== $b

Difference between $a != $b and $a !== $b

$a!=$b

This operator is also known as inequality operator. It is used to check the equality of both operands, however, the type of the operands does not match. For instance, an integer type variable is equivalent to the floating point number if the value of both the operands is same. It is a binary operator. 

PHP




<?php
 
// Assigning values to the
// variables a and b
$a = 5;
$b = 5.0;
 
if($a != $b) {
    echo("Both operands are not Equal");
}
else {
    echo("Both operands are Equal");
}
 
?>


Output

 Both operands are Equal

$a!==$b

This is non-identity operator. It is used to check the equality of both operands, however, the type of the operands also match. For instance, an integer type variable is not equivalent to the floating point number irrespective of the value of both the operands. It is a binary operator. 

PHP




<?php
 
// Assigning the values of
// variables a and b
$a = 5;
$b = 5.0;
 
if($a !== $b) {
    echo("Both operands are not same");
}
else {
    echo("Both operands are same");
}
 
?>


Output

Both operands are not same

Difference between != and !== operators:

!=

!==

It returns true if value of both operands are equal. It returns true if value and data type of both operands are equal.
It is known as Inequality Operator. It is known as Non-identity Operator.
Empty values are considered to be equivalent. Empty values should belong to same data type.

Example: The following code snippet illustrates the difference of both the operators in a simple way. 

PHP




<?php
   
// Assigning values to the
// variables a and b
$a = null;
$b = FALSE;
 
// != operator
if($a != $b) {
    echo("Both operands are not equal (Only Value)\n");
}
else {
    echo("Both operands are equal (Only Value)\n");
}
 
// !== operator
if($a !== $b) {
    echo("Both operands are not equal (Value and Data Types)");
}
else {
    echo("Both operands are equal (Value and Data Types)");
}
 
?>


Output

Both operands are equal (Only Value)
Both operands are not equal (Value and Data Types)
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS