I've always done this:
if ($foo !== $bar)
But I realized that
if ($foo != $bar) is correct too.
= still works and has always worked for me, but whenever I search PHP operators I find no information on double
=, so I assume I've always have done this wrong, but it works anyway. Should I change all my
!= just for the sake of it?
!=do not take into account the data type of the variables you compare. So these would all return true:
!==do take into account the data type. That means comparing a string to a boolean will never be true because they're of different types for example. These will all return false:
You should compare data types for functions that return values that could possibly be of ambiguous truthy/falsy value. A well-known example is