Skip to content

Instantly share code, notes, and snippets.

@moskalukigor
Created December 19, 2017 14:25
Show Gist options
  • Select an option

  • Save moskalukigor/5969374e8fe029424c6d25dc9680c766 to your computer and use it in GitHub Desktop.

Select an option

Save moskalukigor/5969374e8fe029424c6d25dc9680c766 to your computer and use it in GitHub Desktop.
Recursive return parent array by value
<?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