![]() |
VOOZH | about |
The PHP array_search() function searches an array for a specific value and returns the first corresponding key if found. It performs a loose or strict search based on parameters and returns false if the value is not present in the array.
array_search($value, $array, strict_parameter)Parameters: This function takes three parameters as described below:
Return Value: The function returns the key for a given value. If not found, it returns `false`; if multiple matches, the first key.
Example: In this example we defines a function Search() that uses array_search() to find the first occurrence of the value "saran" in the array. It returns the index of the first match, which is 2.
2
Example: This example illustrates the working of function when the strict_parameter is set to FALSE. Note that the data types of the array and to be searched elements are different.
5
Example: In this example, we will be utilizing the above code to find out what will happen if we pass the strict_parameter as TRUE.