search multidimensional array php
snippet in php

search multidimensional array php

user6867

array_search($needle, array_column($array, 'key')); 

//Example
$people = array(
  2 => array(
    'name' => 'John',
    'fav_color' => 'green'
  ),
  5=> array(
    'name' => 'Samuel',
    'fav_color' => 'blue'
  )
);
$found_key = array_search('blue', array_column($people, 'fav_color'));