A little misunderstanding about in_array () judgment

Source: Internet
Author: User
Knowledge needs to be consolidated more, especially some very simple little knowledge. sometimes it is easy to forget it if you don't get in touch for a long time. Today, my colleague encountered a small problem when using in_array (). after checking the information, I found that I still did not remember my basic knowledge.

Knowledge needs to be consolidated more, especially some very simple little knowledge. sometimes it is easy to forget it if you don't get in touch for a long time. Today, my colleague encountered a small problem when using in_array (). after checking the information, I found that I still did not remember my basic knowledge...

Yes. when using in_array ($ k, $ arr) to determine whether $ k is in the $ arr array, when $ k = 0, in_array () is found () returns true. $ Arr does not have the value 0 at the beginning. Later, when I checked the information, I noticed that "when comparing and calculating numbers and strings, PHP will forcibly convert the strings into numbers". The reason is here, because the $ arr array contains all some string values, when using in_array () for determination, php will convert the string to a number before judging. if the string is all non-numeric, php converts it to 0. Therefore, it is understandable that a true value is returned after the result is determined ~~

A little bit of knowledge points directly reflect the shortcomings of your own learning. if you do not have a solid foundation, you will be prone to this "disease", and you will be entangled in problems that shouldn't have been tangled up...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.