PHP - Function in_array()



in_array ( $value,  $array [,$strict ] );

Definition and Usage

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.


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

Return Value

This function returns TRUE if the value is found in the array, or FALSE otherwise.


Try out following example −

   $os = array("Mac", "NT", "Irix", "Linux");
   if (in_array("Irix", $os)) {
      echo "Got Irix";
   if (in_array("mac", $os)) {
      echo "Got mac";

This will produce the following result −

Got Irix