I am trying to create a tree from an array like this:
array(‘admin/home’, ‘admin/home/page’, ‘admin/test’, ‘team/tree/template’, ‘site’);
Or more visually seen as:
admin/home
admin/home/page
admin/test
team/tree/template
site
However, I also need the last nested string of each array to become bolded to signify that it is a webpage itself.
The final product should look like:
admin
home
page
test
team
tree
template
site
I have used a few different solutions from this site but I have not been able to get the right outcome.
Any ideas or examples on where I should start would be greatly appreciated, thanks.
You are probably looking for something like this:
Note that I order the array to make sure that all nested items come next to each other.
It might have some bugs, but I guess you can work them out yourself. Note that I close the list items before opening a nested
<ul>. This is not really how it should; I guess you actually should open the nested<ul>in the final<li>at that level, but you can figure that out yourself.Update I updated the code to properly close the
<ul>‘s in some cases.