A study of In_array function usage in PHP, phpin_array_php tutorial

Source: Internet
Author: User

A probe into the usage of In_array functions in PHP, Phpin_array


This paper probes into the usage of In_array function in PHP. Share to everyone for your reference. Specific as follows:

Today, suddenly think of PHP In_array function has a strange usage, let's look at this usage, the need for a friend simple reference, the code is as follows:
Copy the code as follows: $a =array ("4");
if (In_array (1, $a)) {

echo "condition established";
}
This condition really is set up, according to my thinking logic on the top of the condition only when the value of parameter 1 is "4" and the time is only established, but it is strange that he actually set up, then test the following situation, the code is as follows:
Copy the Code code as follows: $a =array ("a,2,3", "4");

if (In_array (' a ', $a)) {

echo "condition is not established";

}
This is not true, under the first test case, if the parameter 1 is written as a ' 1 ' condition is also not established, the conclusion is:

In PHP, if the first argument is a number--a number without quotation marks, the second array argument contains a string that starts with that number, whether the first argument is the complete element of the second argument, the true value is returned, that is, in_ Does the array function not always match the entire element according to my thinking logic, or do I know the data type well enough?

At the same time, it is also found that if the first element of your array is 0, there will be a problem, as shown in the following code:
Copy the Code code as follows: $a =array (0, "M");
if (In_array (' mc6 ', $a))
{
echo "=====";
}

Interested friends can test run the example described in this article, I believe there will be a new harvest!

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/917036.html www.bkjia.com true http://www.bkjia.com/PHPjc/917036.html techarticle The usage of in_array function in PHP is explored, Phpin_array this paper explores the usage of In_array function in PHP in depth. Share to everyone for your reference. The following: Suddenly thought of PHP today ...

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