w3resource logo

PHP Tutorial

PHP: array_search() function

Secondary Nav

PHP: Searches the array for a given value

The array_search() function is used to search the array against the given value. The function returns the first corresponding key if successful.


(PHP 4 and above)


array_search(value_search, array_name, strict) 


Name Description Required /
value_search Value to search Required Mixed*
array_name Input array name. Required Array
strict If TRUE, checks the type of the value. Default value is FALSE Optional Boolean

Return value

The key for value_search in array_name.

Value Type : Mixed*.

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Pictorial Presentation :

php array array_search() function

Example :

$fruits = array(0 => 'Orange', 1=> 'Apple', 2 => 'Banana',3 => 'Cherry');
$result = array_search('Cherry', $fruits);
echo $result; 

Output :


View the example in the browser

Practice here online :

See also

PHP Function Reference

Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables