| In the php array, how does one find whether an element exists? You can consider using functions such as array_key_exists, in_array, and array_search. This article will give you a brief introduction and a reference for interested friends.
This section describes how to find an element in an array.
In php programming, there are three methods to find whether an element is in an array: the in_array function searches for a given value in the array. In_array (value, array, type) type is optional. If this parameter is set to true, check whether the data to be searched is of the same type as the value of the array.
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.
The array_search' array _ search () function is the same as the in_array () function. you can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.
Note: When the data volume is small, for example, less than 1000, finding which row to use will not become a bottleneck. when the data volume is large, it is more appropriate to use array_key_exists. Of course, here array_key_exists occupies a large amount of memory. it is estimated that the array structure is: Array (1, 2, 3,...) and array (1 => true, 2 => false ,..)
The memory usage ratio is. this is related to the internal implementation. In fact, the first and second data structures in php are similar and are associated with arrays. |