Skip to content

Instantly share code, notes, and snippets.

@Billy-
Created June 22, 2014 15:47
Show Gist options
  • Save Billy-/bc6865066981e80e097f to your computer and use it in GitHub Desktop.
Save Billy-/bc6865066981e80e097f 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;
}
@Billy-
Copy link
Author

Billy- commented Jun 22, 2014

Usage:

$multi_arr = array(array("foo", "bar"), array("baz", "qux"));
echo in_array_r("baz", $multi_array) ? 'found' : 'not found';

http://stackoverflow.com/a/4128377/1879895

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment