Last active
September 29, 2015 03:48
-
-
Save giovanniramos/1542587 to your computer and use it in GitHub Desktop.
Checks if a value exists in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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