PHP function array_search()

Availability in versions: PHP 4.0.5

Searches the array for a given value and returns the corresponding key if successful

Parameters

Parameter Data type Default value Note
$needle mixed not The searched value.
$haystack array not The array.
$strict bool null

Return values

mixed

the key for needle if it is found in the array, false otherwise.

If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys with the optional search_value parameter instead.

Additional resources

Official array-search documentation

Newsletter

Nejlepsi tipy a triky o PHP do Vaseho e-mailu. Clanky a novinky nejen ze sveta PHP a programovani.