Home >Backend Development >PHP Tutorial >php array_search() function usage_PHP tutorial
The array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, returns false.
Prior to PHP 4.2.0, functions returned null instead of false on failure.
If the third parameter strict is specified as true, the key name of the corresponding element will only be returned if the data type and value are consistent.
array_search(value,array,strict)
Parameters | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
value | Required. Specifies the value to search for in the array. | ||||||||
array | Required. The array to be searched. | ||||||||
strict |
If the value is set to true, the type of the given value will also be checked in the array. (See Example 2) |
Output:
Definition and usage The array_search() function is the same as in_array(), searching for a key value in the array. If the value is found, the key of the matching element is returned. If not found, return...