-1

I wonder if there is better (faster) way to search for value in multidimensional array than looping through every item.

Lets say i have

$id_to_search = '16819976033';

And array which is pretty big

Array
(
 [0] => Array
    (
        [id] => Array
            (
                [0] => 16771055710
                [1] => 16776555710
                [2] => 16819976033
            )

        [o] => 21566
        [p] => 12597.66
    )

[1] => Array
    (
        [id] => Array
            (
                [0] => 14089762
            )

        [o] => 12606
        [p] => 1747.49
    )
etc ...
)

I can find it if i loop through each item and than compare them but its very slow because array is big.

MHB2011
  • 453
  • 1
  • 7
  • 22

1 Answers1

2

You can use by array_search function in PHP:

$key = array_search($id_to_search, array_column($YourArray, 'id'));