php - Searching multidimensional array and returning key -


i trying see if value exists in array, , if so, return key:

$letter = 'b';  $array[0]['id'] = 1; $array[0]['find'] = 'a'; $array[1]['id'] = 2; $array[1]['find'] = 'b';  $found = array_search($letter, $array);  if ($found) {     unset($array[$found]);  } 

from can tell, not dropping array elements when value found. suggestions?

if you're looking in specific column:

$found = array_search($letter, array_column($array, 'find')); unset($array[$found]); 
  • this multidimensional array extract find column , search
  • you need loop , unset() if find not unique

or alternately:

$array = array_column($array, null, 'find'); unset($array[$letter]); 
  • extract columns index them find can unset() that

Comments