How to search by key=>value in a multidimensional array in PHP

前端 未结 15 2031
闹比i
闹比i 2020-11-22 00:13

Is there any fast way to get all subarrays where a key value pair was found in a multidimensional array? I can\'t say how deep the array will be.

Simple example arra

15条回答
  •  隐瞒了意图╮
    2020-11-22 00:51

    $result = array_filter($arr, function ($var) {   
      $found = false;
      array_walk_recursive($var, function ($item, $key) use (&$found) {  
        $found = $found || $key == "name" && $item == "cat 1";
      });
      return $found;
    });
    

提交回复
热议问题