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

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


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.


I guess the <> operator has been implemented in PHP because it is present in some other languages (SQL, for instance)

Both <> and != mean almost exactly the same : the only difference I've managed to find is related to their precedence : see Operator Precedence : they are not on the same line ^^ (which means there's a difference, afterall, between those two)

Though, I have to admit I have never seen the <> used in PHP.

Note that people generally use != ; you should probably do the same : it will make your code easier to understand.

And, btw, you also have the !== operator, which does type comparison too ; but there is no <<>> operator or anything like that ^^


As a reference : Comparison Operators


Good question. They are the same, apart from one subtle difference: <> has higher precedence than !=

Why have them? Just to make things work how you might expect. PHP is a mish-mash of borrowed ideas, and where a C programmer might prefer $foo != $bar, someone with a BASIC background might find $foo <> $bar easier on the eye. Each to their own!