What is the difference between != and !== in PHP?

!= (not equal) checks only the value. !== (not identical) checks the value and the data type. So !== is more strict.

<?php
$a = 5;       // integer
$b = "5";     // string

var_dump($a != $b);    // values are same, so false
var_dump($a !== $b);   // data types are different, so true
?>

Output:

Tutorials Class - Output Window

bool(false)
bool(true)

In PHP, <> works same as !=. The same logic applies to the opposite operators, see difference between == and ===.


Learn more about the similar topics:
Tutorials
PHP Operators
PHP Ternary Operator
Exercises & Assignments
Write a PHP program to add two numbers
Interview Questions & Answers
What is the difference between == and === Operators in PHP?
What are the arithmetic operators in PHP?
What is the use of the ternary operator in PHP?
What is the null coalescing operator (??) in PHP?
What is the difference between division (/) and modulus (%) in PHP?
What is the difference between != and !== in PHP?
What is the difference between $var++ and $var + 1 in PHP?