Advertisement
xladomaz

Recursive search

Jul 11th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.40 KB | None | 0 0
  1. function array_search_path_recursive(array $haystack, $needle) {
  2.     foreach ($haystack as $key => $value) {
  3.         if (is_array($value)) {
  4.             $result = array_search_path_recursive($value, $needle);
  5.             if ($result !== false) {
  6.                 return $key . '->' . $result;
  7.             }
  8.         } elseif ($value === $needle) {
  9.             return $key;
  10.         }
  11.     }
  12.     return false;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement