Skip to content

Instantly share code, notes, and snippets.



Last active Apr 11, 2016
What would you like to do?
Collapses a multidimensional array into a simpler array that has the key as the nested dot notation along with it's value.
* Link to original answer by
class ArrUtils {
* @param $array
* @return array
protected function getArrayKeysDotNotation($array)
$arrayIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
$result = array();
foreach ($arrayIterator as $leafValue) {
$keys = array();
foreach (range(0, $arrayIterator->getDepth()) as $depth) {
$keys[] = $key = $arrayIterator->getSubIterator($depth)->key();
$result[ join('.', $keys) ] = $leafValue;
return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment