How does php find matching string elements in a two-dimensional array a high efficiency ratio

Source: Internet
Author: User
Ask how PHP can find matching string elements in a two-dimensional array more efficient
Hello, everyone!
I don't know if this title is right.
The algorithm is not very well understood and wants to find a matching string element in a two-dimensional array.
The structure of the array is this:

Array
2 = Array (
' CatID ' = 2,
' Catdir ' = ' notice ',
)
5 = Array (
' CATID ' = 5,
' Catdir ' = ' subject ',
),
6=> Array (
' CATID ' = 6,
' Catdir ' = ' news '
),
);


is a two-dimensional array, the subscript of the first dimension is the value of the CATID of the second dimension, but not sequential. Now there is a Catdir value to find the corresponding CATID in this array.
At first, a little bit of binary search, but found seemingly impossible.
Ask, what is more effective than traversing an array?

Thank you!


------to solve the idea----------------------
Built-in functions are much more efficient than you can put together in code.
Even if your voice is wrong, the efficiency is highest when you organize your data by query key.
Because the time complexity of the hash table is O (0), and the time complexity of a traversal is O (n)
  • 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.