Thursday, February 9, 2017

php search in a multi dimensional associative array

function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $key => $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return (object) $haystack[$key];
}
}
return false;
}

No comments:

Post a Comment