Logical operators php true or false

前端 未结 4 1649
旧时难觅i
旧时难觅i 2021-01-21 09:39

As a php neewbie , I try to read a lot of other people´s code in order to learn. Today I came across a line like this :

if ( stripos($post_to_check->post_cont         


        
4条回答
  •  孤城傲影
    2021-01-21 09:59

    !== is a comparison that doesn't only compare the value, but also the type of both variables.

    It is used here because stripos can return false when no hit was found, but also 0 when a hit was found in the first character of the string.

    == is unable to distinguish those two cases (they are both "falsy"), so you have to use === when working with stripos. There's a warning in the manual:

    This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

提交回复
热议问题