The array_search()
function searches an array for a given value and returns the corresponding key if the value is found. If the value is found more than once, the first matching key is returned.
The basic syntax of the array_search()
function is given with:
array_search(value, array, strict);
Parameter | Description |
---|---|
value | Required. Specifies the value to search for |
array | Required. Specifies the array to search in |
strict | Optional. If this parameter is set to TRUE, then this function will search for identical elements in the array. Possible values:
|
Example1 :
Output : a
Example 2: Search an array for the value 5 and return its key (notice the " "):
Output : b