Search array and return all keys and values when match found

前端 未结 3 1379
一生所求
一生所求 2021-01-01 22:18

I like to perform a search on an array and return all values when a match is found. The key [name] in the array is what I am doing a search on.

         


        
3条回答
  •  有刺的猬
    2021-01-01 22:54

    $filteredArray = 
    array_filter($array, function($element) use($searchFor){
      return isset($element['name']) && $element['name'] == $searchFor;
    });
    

    Requires PHP 5.3.x

提交回复
热议问题