PHP中高效的多维数组搜索算法实现

I'm looking for an efficient algorithm that allows me to search a multidimensional array for a specific value. I have something like this:

$stuff = array(
    array(
        'id' => 'abc123',
        'name' => 'test'
        'contents' => 'Lorem ipsum'
    ),
    array(
        'id' => 'abc123',
        'name' => 'test'
        'contents' => 'Lorem ipsum'
    ),
    array(
        'id' => 'abc123',
        'name' => 'test'
        'contents' => 'Lorem ipsum'
    ),
    array(
        'id' => 'abc43',
        'name' => 'test'
        'contents' => 'Lorem ipsum'
    ),
    array(
        'id' => 'xyzh31',
        'name' => 'test'
        'contents' => 'Lorem ipsum'
    ),
);

I have to find the item with id = abc43. How can i do this efficiently? Do you know a better algorithm than traversing the entire array?

I think you should use array_multisort() this is as efficient as it could get and I personally use it for searching values in matrices.

You can use array_multisort() as described before, and then implement a binary search algorithm. I will try to describe it in seudocode.

  1. Try in the middle of the (sub)array
  2. If the item is less than the element repeat step 1 in the low part of the array
  3. If the item is less than the element repeat step 1 in the high part of the array