Exploring the usage of in_array function in php, phpin_array_PHP tutorial

WBOY
Release: 2016-07-13 10:13:11
Original
876 people have browsed it

Exploring the usage of in_array function in php, phpin_array

This article explores the usage of in_array function in PHP in depth. Share it with everyone for your reference. The details are as follows:

Today I suddenly thought that the in_array function in PHP has a strange usage. Let’s take a look at this usage. Friends in need can simply refer to it. The code is as follows:

Copy code The code is as follows:
$a=array("1,2,3","4");
if(in_array(1,$a)){

echo "Condition is established";
}

This condition is indeed established. According to my thinking logic, the above condition is only established when the value of parameter 1 is "1, 2, 3" and the sum is 4, but the strange thing is that it is actually established, and then tested In the following situation, the code is as follows:
Copy code The code is as follows:
$a=array("a,2,3","4");

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

echo "The condition is not met";

}

This is not true. In the first test case, if parameter 1 is written as '1', the condition is also not true. The conclusion is:

In PHP, if the first parameter is a number - an unquoted number, and the second array parameter contains a string starting with that number, it does not matter whether the first parameter is the complete second parameter. Elements will return true values. In other words, the in_array function does not match the entire element according to my thinking logic every time, or do I not understand the data type clearly enough?

At the same time, I also found that if the first element of your array is 0, problems will also occur. See the following situation, the code is as follows:

Copy code The code is as follows:
$a=array(0,"m");
if(in_array('mc6',$a))
{
echo "=====";
}

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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917036.htmlTechArticleExploring the usage of in_array function in php, phpin_array This article takes a more in-depth exploration of the usage of in_array function in php. Share it with everyone for your reference. The details are as follows: Today I suddenly thought of...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!