Precautions for using the PHPIN_ARRAY function. In addition, when we control the structure to compare whether two values are always used, we should also try to use them as much as possible (of course, this is also appropriate based on the specific business logic). In addition, when we control the structure to compare whether the two values are consistent, we should also try to use = to Replace = (of course, this is also suitable according to the specific business logic ).
Let's explain why
Var_dump (in_array (0, array ('s '));
The result of this statement is bool (true ).
Because in_array compares 0 and 'S', 0 is the number type, and 'S' is the string type. according to the description in chapter "Comparison Operators" in php manual, number and string
During comparison, the string type is first converted to number before comparison. The result of converting 's' to number is 0, and the result of 0 = 0 is true, so in_array (0, array ('s', 'SS ')) the result is true.
If the third parameter strict of in_array is set to true, the system checks whether the value and type are equal during comparison. True is returned only when the values are equal. otherwise, false is returned.
Note.
When the limit control structure is used to compare whether two values are always used, we should try to use = instead of = (of course, this is also suitable according to the specific business logic )...