Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does PHP have two "not equal to" operators (!= and <>) [duplicate]

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 !=?

like image 959
TigerTiger Avatar asked Aug 11 '09 16:08

TigerTiger


People also ask

What is not equal to operator in PHP?

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.

What is difference between != and <> 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.

Which operator returns false when two operands are not equal?

The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .


1 Answers

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.

like image 102
zombat Avatar answered Oct 16 '22 09:10

zombat