Last active
December 19, 2016 07:20
-
-
Save iampoul/7e64e1d5334dc5a3333e39da412664b7 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* @param array $array | |
* @param string $child | |
* @return array | |
*/ | |
public function find_child_array_values_by_key(array $array, string $child): array | |
{ | |
foreach ( | |
new RecursiveIteratorIterator( | |
new RecursiveArrayIterator($array), | |
RecursiveIteratorIterator::CATCH_GET_CHILD) | |
as $key => $value) | |
{ | |
if($key !== $child && is_array($value)) | |
{ | |
$this->find_child_array_values_by_key($value, $child); | |
} | |
elseif($key === $child && is_array($value)) | |
{ | |
return $value; | |
} | |
else | |
{ | |
return []; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment