What does the exclamation mark before function actually mean PHP?

Just like in the title, what does the exclamation mark before a function mean in PHP?


For example, the following statement:

if (!stripos($haystack, $needle)) {}

      

is the same as:

if (stripos($haystack, $needle) === FALSE) {}

or that:

if (stripos($haystack, $needle) == FALSE) {}


Any clarification would be appreciated

+3


source to share


2 answers


!

preceding the function is the same as ...

if (stripos($haystack, $needle) == FALSE) {}

      

It is the same because it is a comparison ==

that does not check types.

He called the unary negation operator. It flips the Boolean value (coercive the Boolean value if necessary).



For example...

! 0;    // True
! 1 ;   // False
! '';   // True
! true; // False
!! 0    // False 

      

The three is !!

convenient in non-cast languages (bool)

. By flipping the value twice, you get the original Boolean version.

+14


source


! will work on comparing the values, so this is the same as the second comparison. because! will break false, 0, null as false and they are not the same as the types you see. "may be an exception to this, because I always use trim ()! =" "to compare strings. I don't know about that.



0


source







All Articles