Skip to content

Instantly share code, notes, and snippets.

@horlathunbhosun
Forked from Billy-/in_array_r()
Created September 28, 2020 14:55
Show Gist options
  • Save horlathunbhosun/140cac9fb11d98593363655d6bbc3606 to your computer and use it in GitHub Desktop.
Save horlathunbhosun/140cac9fb11d98593363655d6bbc3606 to your computer and use it in GitHub Desktop.
in_array_r() - a multidimensional version of PHP's in_array()
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment