Created
April 17, 2015 07:42
-
-
Save polidog/85359133ffb67769df75 to your computer and use it in GitHub Desktop.
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 | |
function recursive_array_search($needle, array $haystack) { | |
foreach ($haystack as $key => $value) { | |
if ($value === $needle) { | |
return $key; | |
} | |
if (is_array($value)) { | |
$chideKey = recursive_array_search($needle, $value); | |
return [$key, $chideKey]; | |
} | |
} | |
} | |
$data = [ | |
'a', | |
'b', | |
[ | |
'aa', | |
'bb' | |
] | |
]; | |
$ret = recursive_array_search('bb', $data); | |
var_dump($ret); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment