1) { $key = array_shift($keys); if ( ! isset($array[$key])) { $array[$key] = array(); } $array =& $array[$key]; } $array[array_shift($keys)] = $value; } }