Home >Backend Development >PHP Tutorial >Is there a function to determine whether a number is in a known array?_PHP Tutorial
bool in_array (mixed needle, array haystack [, bool strict])
Search for needle in haystack and return TRUE if found, otherwise return FALSE.
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: Before 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";
}