Which efficiency of in_array and array_keys can be used to determine whether a corresponding value exists in a million-level numeric array faster? for example, question. please advise! Which of in_array and array_keys is more efficient?
Determine whether a corresponding value exists in a million-level numeric array, such as the question. ask for advice! Share:
------ Solution --------------------
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
------ Solution --------------------
Reference:
Quote: reference:
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
The latter can have repeated values. an array is returned. I have tested it and can have the same value.
Try it. if possible, report a bug to the official website.
------ Solution --------------------
Reference:
Quote: reference:
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
The latter can have repeated values. an array is returned. I have tested it and can have the same value.
Where is the duplicate value of key ???
------ Solution --------------------
Reference:
Quote: reference:
Quote: reference:
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
The latter can have repeated values. an array is returned. I have tested it and can have the same value.
Try it. if possible, report a bug to the official website.
Hahaha, you are so crazy...
------ Solution --------------------
Its second parameter is optional. if it is null, an array consisting of all key names is returned. If this parameter is specified, as required, only the corresponding key name is returned.
------ Solution --------------------
Is this solution suitable for your needs?
------ Solution --------------------
What business do you do? put it all in the array, occupying the memory. it's better to get what you need in the database.
------ Solution --------------------
The great gods on the first floor are right.
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
If the array contains duplicate key values, you can obtain the value corresponding to the last key when using the key-value method, however, when array_keys is used to obtain the key, the key that appears for the first time is returned.
In addition, such a large amount of data can be stored in nosql such as memcache. the speed is fast enough and your requirements are fully satisfied. you can get it to know if it exists.
------ Solution --------------------
Reference:
The great gods on the first floor are right.
In_array is a sequential query.
Array_keys is used to query hash tables.
The latter is faster, but the latter cannot have repeated values.
If the array contains duplicate key values, you can obtain the value corresponding to the last key when using the key-value method, however, when array_keys is used to obtain the key, the key that appears for the first time is returned.
In addition, such a large amount of data can be stored in nosql such as memcache. the speed is fast enough and your requirements are fully satisfied. you can get it to know if it exists.