Array_search () Definition and usage
The Array_search () function, like In_array (), looks for a key value in the array. If the value is found, the key name of the matching element is returned. Returns False if it is not found.
Before PHP 4.2.0, the function returns null instead of false on failure.
If the third argument strict is specified as true, the key name of the corresponding element is returned only if both the data type and the value are consistent.
Grammar
Array_search (value,array,strict) parameter description
Value required. Specify the values to search for in the array.
Array required. The array being searched.
Strict optional. Possible values:
True
False-Default
If the value is set to True, the type of the given value is also checked in the array. (see Example 2)
Example 1
Copy Code code as follows:
<?php
$a =array ("a" => "Dog", "B" => "Cat", "C" => "horse");
Echo Array_search ("Dog", $a);
?>
Output:
A