In fact, the key is because php is a weak language. it is best to use the strict method when comparing php. This will not only compare the value of the two, but also compare the type of the two. In addition, when controlling whether the two values are always in the structure, we should try to use = instead of = (of course, this is also appropriate based on the specific business logic ).
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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service