Skip to content

Instantly share code, notes, and snippets.

@polidog
Created April 17, 2015 07:42
Show Gist options
  • Save polidog/85359133ffb67769df75 to your computer and use it in GitHub Desktop.
Save polidog/85359133ffb67769df75 to your computer and use it in GitHub Desktop.
<?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