PHP search for Key in multidimensional array

前端 未结 3 842
花落未央
花落未央 2020-12-12 06:29

I have this:

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

        )

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

            


        
3条回答
  •  無奈伤痛
    2020-12-12 07:15

    So you don't you your id key for the first level, so loop through and when you find a match stop looping and break out of the foreach

    $id = 0;
    $needle = 63;
    foreach($array as $i => $v)
    {
        if ($v['no'] == $needle)
        {
            $id = $i;
            break 1;
        }
    }
    // do what like with any other nested parts now
    print_r($array[$id]);
    

    Then you could use that key to get the whole nested array.

提交回复
热议问题