The string
$string = \'a.b.c.d\';
should create an array like
array(\'a\' => array(\'b\' => array( ....
I managed
It's still pretty unclear, but if you only want what you have asked for:
function convertToArray($string)
{
$pos = strpos($string, '.');
$key = substr($string, 0, $pos);
$result = array($key => array());
if ($pos === false) {
return array($string=>array());
} else {
$result[$key] = convertToArray(substr($string, ($pos+1)));
return $result;
}
}
var_dump(convertToArray('a.b.c.d'));
Will ouput:
array(1) {
["a"]=>
array(1) {
["b"]=>
array(1) {
["c"]=>
array(1) {
["d"]=>
array(0) {
}
}
}
}
}