PHP in_array() Function

The in_array() function searches an array for a specific value. If the third parameter strict is set to TRUE then the in_array() function will also check the types of the $value.

Note: If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.

Parameter Description
search Required. Specifies the what to search for
array Required. Specifies the array to search
type Optional. If this parameter is set to TRUE, the in_array() function searches for the search-string and specific type in the array.

Syntax

in_array(search,array,type) 

Example

$name = array("Prince", "Cooper", "Samuel", "Alex");   
if (in_array("Prince", $name)) {
   echo "Name Prince";
}
if (in_array("Samuel", $name)) {
   echo "Name Samuel";
}

Output

Name Prince
Name Samuel

Leave a Reply

Your email address will not be published. Required fields are marked *