Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created December 27, 2010 20:25
Show Gist options
  • Save shanestillwell/756518 to your computer and use it in GitHub Desktop.
Save shanestillwell/756518 to your computer and use it in GitHub Desktop.
Recursive Array Search
// 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