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
use the recursion Luke
function ins(&$ary, $keys, $val) {
$keys ?
ins($ary[array_shift($keys)], $keys, $val) :
$ary = $val;
}
// test
$arr['alfa.xray.uno'] = "Alfa X-Ray Uno";
$arr['alfa.yaho.duo'] = "Alfa Yaho Duo";
$arr['beta.xray.uno'] = "Beta X-Ray Uno";
$arr['beta.xray.duo'] = "Beta X-Ray Duo";
$arr['just-me'] = "Root-level item";
$a = array();
foreach($arr as $k => $v)
ins($a, explode('.', $k), $v);
print_r($a);