Just as in the title, what does an exclamation mark before a function really mean in PHP?
For example is the following statement:
if (!stripos($haystack, $needle)) {}
the same as this:
if (stripos($haystack, $needle) === FALSE) {}
or this:
if (stripos($haystack, $needle) == FALSE) {}
Any clarification would be appreciated
The
!preceding the function is the same as…It’s the same because it is a
==comparison which doesn’t check types.It’s called the negation unary operator. It flips the Boolean value (coercing to Boolean if need be) of a value.
For example…
The
!!trick is handy in languages without a(bool)cast. By flipping a value twice, you get the Boolean version of its original value.