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 |
| Exercises & Assignments |
|---|
| Write a PHP program to add two numbers |
| Write a PHP program to check whether a number is positive, negative or zero |