Javatpoint Logo
Javatpoint Logo

PHP array_search() function

The array_search() function is an inbuilt function of PHP. It is used to search the array against the given value. The function returns the first corresponding key if successful. This function was introduced in PHP 4.0.5.

Syntax

Parameter

Parameter Description Is compulsory
Value search Value to search. compulsory
array name Input array name. compulsory
strict If TRUE, checks the type of the value. The default value is FALSE. Optional

Return type

The array_search() function returns the key of the corresponding value that is passed. If not found, FALSE is returned, and if there are more than one matches, the first matched key is returned.

Example 1

Output:

3

Example 2

Output:

a

Example 3

Output:

b

Example 4

Output:

5





Help Others, Please Share

facebook twitter pinterest