Return to Snippet

Revision: 28902
at July 16, 2010 01:00 by iloveitaly


Initial Code
function array_search_key($needle, $haystack, $haystackKey, $strict = false) {
	foreach($haystack as $key => $value) {
		if(isset($value[$haystackKey])) {
			if($strict) {
				if($value[$haystackKey] === $needle) return true;
			} else {
				if($value[$haystackKey] == $needle) return true;
			}
		}
	}
	
	return false;
}

Initial URL

                                

Initial Description
like array_search but compares against a specific key in each element of the array

Initial Title
Array Search on Key

Initial Tags
search, array

Initial Language
PHP