I just happened to stumbled upon a piece of php code and could see author used <>
to do a not equal to comparison:
if ($variable <> "") {
echo "Hello, I am having some value";
}
I have always used !=
:
if ($variable != "") {
echo "Hello, I am having some value";
}
Are there any special circumstances, when I should use <>
over !=
?
Introduction to PHP not equal. One of the comparison operators in PHP is not equal, which is represented by the symbol != or <> and whenever we want to compare the data types of the two given values, we make use of not equal operator in PHP.
==' operator checks the unequality of two objects with a type check. It does not converts the datatype and makes a typed check. For example 1 !== '1' will results true.
The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
I believe when PHP was first developed, one of the design goals was to make the language flexible, which is why they brought in every loop type and every operator type you could possibly think of.
<>
is slightly different than !=
in terms of precedence category, but the operators that come between them means that there is no practical difference whatsoever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With