Array_search () searches for a given value in the array and returns the corresponding key name. [function] This function searches for a given value in the specified array, if it is found, the key name of the value is returned. otherwise, false is returned. [Scope of use] php4 & gt; 4.0.5, php5. [use] mixed... SyntaxHighlighter
Array_search () searches for the given value in the array and returns the corresponding key name.
[Function]
This function searches for a given value in the specified array and returns the key name of the value if it is found. otherwise, false is returned.
Scope of use]
Php4> = 4.0.5, php5.
[Use]
Mixed array_search (mixed needle, array haystack [, bool strict])
Needle/required/value to be searched
Haystack/required/original array to be searched
Strict/optional/true then the function will also check the needle type in haystack
If needle appears more than once in the haystack, the first matched creation is returned.
[Example]
[Php]
$ Array = array ('blue', 'red', 'green', 'red ');
Echo $ key = array_search ('green', $ array );
Echo "\ n ";
Echo $ key = array_search ('red', $ array, false );
/*
2
1
*/
Taken from zuodefeng's note