Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
Created May 30, 2014 18:06
Show Gist options
  • Save jasonrhodes/ad8a6922e05c4be30b2f to your computer and use it in GitHub Desktop.
Save jasonrhodes/ad8a6922e05c4be30b2f to your computer and use it in GitHub Desktop.
Take a list of strings and turn it into a nested associative array
<?php
function nestify($list, &$master) {
if (empty($list)) {
return $master;
}
$key = array_shift($list);
if (empty($master[$key])) {
$master[$key] = array();
}
nestify($list, $master[$key]);
}
$meta = array("region" => array("blah" => "duh"));
$list = ["region", "hero", "thing"];
nestify($list, $meta);
print_r($meta);
@jasonrhodes
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment