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)