What is the difference between !=
and <>
? Which one should I use?
What is the difference between !=
and <>
? Which one should I use?
According to the PHP documentation both are comparison operators and serve to compare if one value is different from another.
Example (using the var_dump()
function to return the result):
<?php
var_dump( 7 != 7 ); // FALSE, pois não são diferentes
var_dump( 7 != 6 ); // TRUE, pois são diferentes
var_dump( 7 <> 7 ); // FALSE, pois não são diferentes
var_dump( 7 <> 6 ); // TRUE, pois são diferentes
?>
The usage varies depending on your preference, but the most common is to use !=
.
You can see more about directly in the PHP documentation here
strong> and about precedence here. None, are exact synonyms. It's just different ways of writing. Choose which one you find most comfortable. I see that it is more common to use !=
to be symmetric with ==
("equal"), since !=
would be the same as say "not equal".