I have a standard array with key-value pairs - and I want to use the keys to transform it into a multi-dimensional array. The difficulty seems to be that I need to loop recu
You could use references to successively iterate through and build up the nested array structure:
$out = array(); foreach ($arr as $key=>$val) { $r = & $out; foreach (explode(".", $key) as $key) { if (!isset($r[$key])) { $r[$key] = array(); } $r = & $r[$key]; } $r = $val; } return $out;