Home  >  Article  >  Backend Development  >  Function to determine whether a number is in a known array_PHP Tutorial

Function to determine whether a number is in a known array_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:33804browse

​ bool in_array (mixed needle, array haystack [, bool strict])
Searches the haystack for needle and returns TRUE if found, FALSE otherwise.
If the value of the third parameter strict is TRUE, the in_array() function will also check whether the type of needle is the same as that in haystack.
Note: If needle is a string, the comparison is case-sensitive.
Note: Prior to PHP version 4.2.0, needle was not allowed to be an array.
Example 1. in_array() example
$os = array ("Mac", "NT", "Irix", "Linux");
if (in_array ("Irix", $os)) {
print "Got Irix";
}
if (in_array ("mac", $os)) {
print "Got mac";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445598.htmlTechArticlebool in_array (mixed needle, array haystack [, bool strict]) Search needle in haystack and return if found TRUE, otherwise returns FALSE. If the value of the third parameter strict is...
Statement:
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