Check if a specific value exists at a specific key in any subarray of a multidimensional array
Nothing will be faster than a simple loop. You can mix-and-match some array functions to do it, but they'll just be implemented as a loop too.
function whatever($array, $key, $val) { foreach ($array as $item) if (isset($item[$key]) && $item[$key] == $val) return true; return false;}
Here is an updated version of Dan Grossman's answer which will cater for multidimensional arrays (what I was after):
function find_key_value($array, $key, $val){ foreach ($array as $item) { if (is_array($item) && find_key_value($item, $key, $val)) return true; if (isset($item[$key]) && $item[$key] == $val) return true; } return false;}
** PHP >= 5.5
simply u can use this
$key = array_search(40489, array_column($userdb, 'uid'));
Let's suppose this multi dimensional array:
$userdb=Array((0) => Array ( (uid) => '100', (name) => 'Sandra Shush', (url) => 'urlof100' ),(1) => Array ( (uid) => '5465', (name) => 'Stefanie Mcmohn', (pic_square) => 'urlof100' ),(2) => Array ( (uid) => '40489', (name) => 'Michael', (pic_square) => 'urlof40489' ));$key = array_search(40489, array_column($userdb, 'uid'));