Created
February 19, 2013 12:22
-
-
Save mheap/4985392 to your computer and use it in GitHub Desktop.
Convert multidimensional array to 2D array with dot notation keys (via http://stackoverflow.com/a/10424516)
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
<?php | |
$ritit = new RecursiveIteratorIterator(new RecursiveArrayIterator($myArray)); | |
$result = array(); | |
foreach ($ritit as $leafValue) { | |
$keys = array(); | |
foreach (range(0, $ritit->getDepth()) as $depth) { | |
$keys[] = $ritit->getSubIterator($depth)->key(); | |
} | |
$result[ join('.', $keys) ] = $leafValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment