PHP function array_search()

11. 9. 2019

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

Jan Barášek
Jan BarášekVíce o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

Newsletter

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