phparraysmultidimensional-arrayfilter

Return the first level key when a column value is found in a 2d array


I have this:

Array
(
    [carx] => Array
        (
            [no] => 63
       
        )

    [cary] => Array
           (
           [no] => 64
   
           )
)

How can I find the key carx when I have the no=63? I know how to use array_search() but this one is a bit tricky.

Like I can find key name id while I have 63 But this one is a bit tricky.


Solution

  • foreach ($array as $i => $v) $array[$i] = $v['no'];
    $key = array_search(63, $array);