1. the array_searchmixedarray_search (mixed $ needle, array $ haystack [, bool $ strictfalse]) function searches for a given value in the array. if it succeeds, the corresponding key name is returned in & nbsp; haystack & nbsp; In Search 1. array_search
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
Function
Search for the given value in the array. if the value is successful, the corresponding key name is returned.
Description
In?haystack? Search in?needle? Parameters.
Parameters
needle——Search value. (Note: If?needle? Is a string, the comparison is case sensitive)
haystack——This array.
strict——If the third parameter is optional?strict? Is it?TRUE, Then?Array_search ()? In?haystack? CheckIdentical. Which means the same check?haystack? In?needle? ? Type, and the object must be the same instance.
Return value
If yes?needle? Returns its key; otherwise, it returns?FALSE.
If?needle? In?haystack? Returns the first matched key. To return keys of all matched values, use? Array_keys ()? What are the optional parameters?search_value? .
II. in_array
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Function
Check whether a value exists in the array.
Description
In?haystack? Search in?needle?strict? Then use loose comparison.
Parameters
needle——The value to be searched. (Note: If?needle? Is a string, the comparison is case sensitive)
haystack——This array.
strict——If the third parameter?strict? The value is?TRUE? Then?In_array ()? Will the function check?needle? Is the type?haystack? .
Return value
If you find?needle? ?TRUEOtherwise, return?FALSE.
III. Sample code
"A", 2 => "B", 3 => "c"); $ arr3 = array (1 => "abc"); if (in_array ($ v, $ arr1) {echo "v in arr1 \ n";} else {echo "v not in arr1 \ n";} if (in_array ($ v, $ arr2 )) {echo "v in arr2 \ n";} else {echo "v not in arr2 \ n";} if (array_search ($ v, $ arr1 )) {echo "found v in arr1 \ n";} else {echo "found nothing \ n";} if (array_search ($ v, $ arr2 )) {echo "found v in arr2 \ n";} else {echo "found nothing \ n";} if (array_search ($ v, $ arr3 )){ Echo "found v in arr3 \ n";} else {echo "found nothing \ n" ;}?>
Print result:
v not in arr1v in arr2found nothingfound v in arr2found nothing