PHP array_search() Function

PHP array_search() Function

The array_search() function in PHP searches the array for the specified value. This function returns the first corresponding key if the value is found.

Syntax

Parameter

needle(required)– This parameter represents the value to search.

haystack(required)– This parameter signifies the input array.

strict(optional)– This parameter signifies the strictness of the search. It takes only Boolean values which are as follows:

  • If it is set to Boolean TRUE, the function checks only for identical elements.
  • If set to Boolean FALSE(default), strictness is not maintained.

Return

This function returns the first corresponding key if the needle value is found else it returns false.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output