There are many methods to find the specified value in the array in php. next I will introduce the array search function in_array (), array_key_exists (), array_search () in php () the following three methods are used to query whether an element is in an array:
There are many methods to find the specified value in the array in php. next I will introduce the array search function in_array (), array_key_exists (), array_search () usage in php.
There are three methods to check whether an element is in an array:
The in_array 'function searches for the given value in the array. in_array (value, array, type) type is optional. if this parameter is set to true, check whether the searched data is of the same type as the array value.
The array_key_exists 'Array _ key_exists () function checks whether a specified key exists in an array. if the key exists, true is returned. otherwise, false is returned. array_key_exists (key, array) Example #1 array_key_exists () Example
The instance code is as follows:
-