PHP In_array Function Usage Considerations _php Tutorial

Source: Internet
Author: User
Also, we should try to use = = = to replace = = (Of course, this is also appropriate according to the specific business logic) when we compare two values in the control structure.

Little brother to 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 the number type, ' s ' is a string type, and according to the instructions in the chapter "Comparison Operators" in PHP Manual, number and string are

When comparing, the string type is first converted to number, and then the comparison operation. The result of ' s ' conversion 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 of In_array is set to True, the comparison will determine whether the value and type are equal. Returns true if all are equal, otherwise returns false.

This is the only record.

http://www.bkjia.com/PHPjc/322204.html www.bkjia.com true http://www.bkjia.com/PHPjc/322204.html techarticle In addition, we in the control structure to compare two values are always, should try to use = = = to replace = = (Of course, this also according to the specific business logic selection is more appropriate) ...

  • 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.