I have an array which is dynamically generated by parsing a web page:
titles Array
(
[0] => bookmarks
[1] => New Folder
[2] => New Folder2
)
and I want to insert html links into another, nultidemensional array
which is based on the first array:
$dl[$titles[0]][$titles[1]][$titles[2]]=$link;
However this only works if the titles array has exactly 3 members.
So I made this switch:
$num=sizeof($titles);
switch($num){
case 1:
$dl[$titles[0]][]=$link;
break;
case 2:
$dl[$titles[0]][$titles[1]][]=$link;
break;
case 3:
$dl[$titles[0]][$titles[1]][$titles[2]][]=$link;
break;
}
This works pretty good as long as I expand the switch to have more cases
than largest possible size for the titles array. However, I can't help
feeling that there must be a better way, something which would custom
generate the multidemensional array each time I insert data into it.
This is rediculous, but it might give you the idea of what I am looking
for:
foreach($titles as $title){
$dl.="[$title]";
}
$dl[]=$link;
Is this possible in PHP ?
red