Search for values in nested array

后端 未结 6 1345
滥情空心
滥情空心 2020-12-21 01:07

I have an array as follows

array(2) {
  [\"operator\"] => array(2) {
    [\"qty\"] => int(2)
    [\"id\"] => int(251)
  }
  [\"accessory209\"] =>         


        
6条回答
  •  情歌与酒
    2020-12-21 01:12

    $map = array();
    foreach ($arr as $v) {
        $map[$v['id']] = 1;
    }
    //then you can just do this as when needed
    $exists = isset($map[211]);
    

    Or if you need the data associated with it

    $map = array();
    foreach ($arr as $k => $v) {
        $map[$v['id']][$k] = $v;
    }
    print_r($map[211]);
    

提交回复
热议问题