October 2005
Intermediate to advanced
372 pages
11h 35m
English
in_array()
bool in_array ( mixedneedle, arrayhaystack[, boolstrict] )
The in_array() function will return true if an array contains a specific value; otherwise, it will return false:
$needle = "Sam";
$haystack = array("Johnny", "Timmy", "Bobby", "Sam", "Tammy", "Joe");
if (in_array($needle, $haystack)) {
print "$needle is in the array!\n";
} else {
print "$needle is not in the array\n";
}There is an optional boolean third parameter for in_array() (set to false by default) that defines whether you want to use strict checking or not. If parameter three is set to true, PHP will return true only if the value is in the array and of the same type—that is, if they are identical in the same way as the = = = operator (three equals signs).