Skip to content

Instantly share code, notes, and snippets.

@mheap
Created February 19, 2013 12:22
Show Gist options
  • Save mheap/4985392 to your computer and use it in GitHub Desktop.
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)
<?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