Skip to content

Instantly share code, notes, and snippets.

@giovanniramos
Last active September 29, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovanniramos/1542587 to your computer and use it in GitHub Desktop.
Save giovanniramos/1542587 to your computer and use it in GitHub Desktop.
Checks if a value exists in an array
<?php
/**
* Checks if a value exists in an array
*
* @param mixed $needle The value sought
* @param array $haystack The array that will be verified
* @return boolean
*
* */
function in_multiarray($needle, $haystack)
{
$top = sizeof($haystack) - 1;
$bottom = 0;
while ($bottom <= $top) {
if ($haystack[$bottom] == $needle) {
return true;
} else {
if (is_array($haystack[$bottom])) {
if (in_multiarray($needle, ($haystack[$bottom]))) {
return true;
}
}
}
$bottom++;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment