Find all the values of a key in an array

This is a recursive PHP function that searches all of the keys in an array and pulls out their values.

function multi_array_key_search($needle,$haystack,$keys_found=array()){
	if(is_array($haystack)){
		foreach($haystack as $key=>$val){
			if(is_array($val)){
				$keys_found = multi_array_key_search($needle,$val,$keys_found);
			}else{
				if($key==$needle){
					$keys_found[] = $val;
				}
			}
		}
		return $keys_found;
	}
	return false;<br />
}

View Comments · Tags: ,