Created
December 19, 2017 14:25
-
-
Save moskalukigor/5969374e8fe029424c6d25dc9680c766 to your computer and use it in GitHub Desktop.
Recursive return parent array by value
This file contains hidden or 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_return_parent_array_by_value($needle, $haystack) { | |
| $return = false; | |
| foreach ($haystack as $key => $val) { | |
| if (is_array($val)) { | |
| $return = recursive_return_parent_array_by_value($needle, $val); | |
| if( isset($return['found']) ) | |
| return $return; | |
| } elseif ($needle == $val) { | |
| return array('found' => $haystack); | |
| } | |
| } | |
| return $return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment