English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_search() function searches for a given value in an array and returns the first matching key name if successful.
array_search($value, $array [,$strict]);
The array_search() function searches for a value in an array and returns the key.
Serial Number | Parameters and Description |
---|---|
1 | value (required) It specifies the value to be searched. |
2 | array (required) It specifies an array. |
3 | strict (optional) If set to true, array_search() will also check the search type in the array. |
If it finds it in the array, it returns the key; otherwise, it returns FALSE.
If the value appears more than once in the array, it returns the first matching key. To return all matching keys, use array_keys() with an optional parameter search_value instead.
Search for a given value in an array
<?php $input = array("a" => "banana", "b" => "apple", "c" => "Mango"); print_r(array_search("apple", $input)); ?>Test and See‹/›
Output Result:
b