Created
December 27, 2010 20:25
-
-
Save shanestillwell/756518 to your computer and use it in GitHub Desktop.
Recursive Array Search
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
// Recursivly search through an array, if the key is found, then return TRUE | |
private function _recursiveArraySearch($haystack, $needle, $index = null) | |
{ | |
$aIt = new RecursiveArrayIterator($haystack); | |
$it = new RecursiveIteratorIterator($aIt); | |
while($it->valid()) | |
{ | |
if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { | |
//return $aIt->key(); | |
return TRUE; | |
} | |
$it->next(); | |
} | |
return FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment