Solution:1
$a = array(
"Courses",
"Courses/PHP",
"Courses/PHP/Array",
"Courses/PHP/Functions",
"Courses/JAVA",
"Courses/JAVA/String");
$result = array();
foreach($a as $item){
$itemparts = explode("/", $item);
$last = &$result;
for($i=0; $i < count($itemparts); $i++){
$part = $itemparts[$i];
if($i+1 < count($itemparts))
$last = &$last[$part];
else
$last[$part] = array();
}
}
var_dump($result);
The result is:
array(1) {
["Courses"]=>
array(2) {
["PHP"]=>
array(2) {
["Array"]=>
array(0) {
}
["Functions"]=>
array(0) {
}
}
["JAVA"]=>
&array(1) {
["String"]=>
array(0) {
}
}
}
}