I have a simple array in PHP like this :
Array
(
[max_size_video] => 50000
[max_size_photo] => 8000
[token_expire] => 100
[dns] => mydns.fr
...
)
I would like to convert this array to multidimensional format with underscore as a separator:
Array
(
[max] => Array
(
[size] => Array
(
[video] => 50000
[photo] => 8000
)
)
[token] => Array
(
[expire] => 100
)
[dns] => mydns.fr
...
)
I can do this with the following ugly code :
$item = explode('_', $row);
switch (count($item)) {
case 1:
$array[$item[0]] = $value;
break;
case 2:
$array[$item[0]][$item[1]] = $value;
break;
case 3:
$array[$item[0]][$item[1]][$item[2]] = $value;
break;
case 3:
$array[$item[0]][$item[1]][$item[2]][$item[3]] = $value;
break;
...
}
How can I do this with a more elegant function?