This article mainly introduces the PHP search and search for array elements. The example summarizes the usage techniques of function operation arrays such as in_array, array_key_exists, array_search, array_keys, and array_values in php, for more information about how to search for array elements in PHP, see the following example. Share it with you for your reference. The specific analysis is as follows:
Searching, filtering, and searching array elements are common functions of array operations. The following describes several related functions.
In_array () function
The in_array () function searches for a specific value in an array. if this value is found, true is returned. otherwise, false is returned. The format is as follows:
The code is as follows:
Apple's color is red
Array_search () function
The array_search () function searches for a specified value in an array. If yes, the corresponding key is returned. otherwise, false is returned. The format is as follows:
The code is as follows:
Watermelon was founded on green.
Array_keys () function
The array_keys () function returns an array containing all the keys found in the searched array. The format is as follows:
The code is as follows:
Array ([0] => apple [1] => banana [2] => watermelon)
Array_values () function
The array_values () function returns all values in an array and automatically provides a numerical index for the returned array. The format is as follows:
The code is as follows:
Array ([0] => red [1] => yellow [2] => green)
I hope this article will help you with php programming.