This paper probes into the usage of In_array function in PHP. Share to everyone for your reference. Specifically as follows:
Today, I suddenly think of PHP In_array function has a strange usage, let's take a look at this usage, the need for a simple reference to friends, the code is as follows:
Copy Code code as follows:
$a =array ("1,2,3", "4");
if (In_array (1, $a)) {
echo "Conditional establishment";
}
This condition is indeed set up, according to my thinking the logic above the condition only in the value of parameter 1 is "1,2,3" and 4, but it is strange that he actually set up, and then test the following situation, the code is as follows:
Copy Code code as follows:
$a =array ("a,2,3", "4");
if (In_array (' a ', $a)) {
echo "condition is not tenable";
}
This is not tenable, in the first test case, if the parameter 1 written ' 1 ' condition is also not tenable, the conclusion is:
In PHP, if the first argument is a number--no quotes, the second array argument contains a string that begins with that number. The true value is returned regardless of whether the first argument is a complete element of the second argument, that is, in_ Does the array function not always match the whole element in my thinking logic, or do I not know the data type well enough?
At the same time, also found that if your array of the first element of 0, there will be problems, look at the following situation, the code is as follows:
Copy 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 will help you with your PHP program design.