Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Last active December 13, 2018 17:01
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 bzerangue/44639f50ba555ba25d1c57931e519fe3 to your computer and use it in GitHub Desktop.
Save bzerangue/44639f50ba555ba25d1c57931e519fe3 to your computer and use it in GitHub Desktop.
PHP: Recursive Array Search Function
<?php
/*
=====
Find integer value of array key for search term in the $needle.
=====
*/
function recursive_array_search($needle,$haystack) {
foreach($haystack as $key=>$value) {
$current_key=$key;
if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) {
return $current_key;
}
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment