Which of the following is the efficiency of in_array and array_keys?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.