Last active
December 13, 2018 17:01
-
-
Save bzerangue/44639f50ba555ba25d1c57931e519fe3 to your computer and use it in GitHub Desktop.
PHP: Recursive Array Search Function
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 | |
/* | |
===== | |
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