Home  >  Article  >  Backend Development  >  Notes on using arrayadapter PHP IN_ARRAY function

Notes on using arrayadapter PHP IN_ARRAY function

WBOY
WBOYOriginal
2016-07-29 08:43:26966browse

In addition, when we control the structure to compare whether two values ​​​​are consistent, we should also try to use === instead of == (of course, this should also be selected according to the specific business logic).
Brother, please explain why
var_dump(in_array(0, array('s' ));
The result of this sentence is bool(true).
Because in_array will compare 0 and 's', 0 is number type, 's' is a string type. According to the description in the "Comparison Operators" chapter in the PHP manual, when comparing number and string, the string type will be converted to number first, and then the 's' conversion operation will be performed. The result of number is 0, and the result of 0 == 0 is true, so the result of in_array(0, array('s', 'ss')) is also true
If the third parameter strict of in_array is set to true , when comparing, it will be judged whether the values ​​and types are equal. If they are equal, it will return true, otherwise it will return false.
This is just a note.
The above introduces the precautions for using arrayadapter PHP IN_ARRAY function, including the content of arrayadapter. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn