PHP array_search Function

PHP array_search Function


The array_search() function searches an array for a given value and returns the corresponding key if the value is found. If the value is found more than once, the first matching key is returned.

Syntax

The basic syntax of the array_search() function is given with:

      array_search(valuearraystrict);

Parameter 
Parameter Description
value Required. Specifies the value to search for
array Required. Specifies the array to search in
strict Optional. If this parameter is set to TRUE, then this function will search for identical elements in the array. Possible values:
  • true
  • false - Default

Example1 : 

Output : a

Example 2: Search an array for the value 5 and return its key (notice the " "):

Output : b