Easy Tutorial
❮ Func Math Lcg Value Func Xml Parser Create ❯

PHP array_search() Function

Complete PHP Array Reference Manual

Example

Search for the value "red" in the array and return its key:


Definition and Usage

The array_search() function searches for a given value in an array and returns the corresponding key.


Syntax

Parameter Description
value Required. The value to search for in the array.
array Required. The array to be searched.
strict Optional. If set to TRUE, the function searches for elements with both the same data type and value in the array. Possible values: true<br>false - default. If set to true, it checks the type of the given value in the array; the number 5 and the string "5" are considered different (see Example 2).

Technical Details

Return Value: Returns the key corresponding to the value if found in the array, otherwise returns FALSE. If the value is found more than once in the array, it returns the key of the first occurrence.
PHP Version: 4.0.5+
--- ---
Changelog: Returns NULL if invalid parameters are passed to the function (applies to all PHP functions since PHP 5.3.0). <br> <br>Since PHP 4.2.0, the function returns FALSE instead of NULL if the search fails.
--- ---

More Examples

Example 1

Search for the value 5 in the array and return its key (note the ""):


❮ Func Math Lcg Value Func Xml Parser Create ❯