Home  >  Article  >  Backend Development  >  Things to note about the IN_ARRAY function in php

Things to note about the IN_ARRAY function in php

WBOY
WBOYOriginal
2016-07-25 08:51:59875browse
  1. var_dump(in_array(0, array('s' ));
Copy code

Result: bool(true).

Because in_array will compare 0 and 's', 0 is a number type, and 's' is a string type. According to the instructions in the "Comparison Operators" chapter in the php manual, number and string are compared

When comparing, the string type will be converted to number first, and then the comparison operation will be performed. The result of converting 's' to 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, the comparison will determine whether the values ​​and types are equivalent. If they are all equal, true will be returned, otherwise false will be returned.

Let me introduce these. Some of the problems I encountered in my studies, I also hope to share with friends who encounter similar problems.



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