Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement