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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -