How do you build a hierarchical set of tags with data in PHP?
For example, a nested list:
<div> <ul> <li>foo </li> <li>bar <ul> <li>sub-bar </li> </ul> </li> </ul> </div>
This would be build from flat data like this:
nested_array = array(); nested_array[0] = array('name' => 'foo', 'depth' => 0) nested_array[1] = array('name' => 'bar', 'depth' => 0) nested_array[2] = array('name' => 'sub-bar', 'depth' => 1)
It would be nice if it were nicely formatted like the example, too.
Edit: Added formatting
As already said in the comments, your data structure is somewhat strange. Instead of using text manipulation (like OIS), I prefer DOM:
Your formatting convention is kind of strange. Replace the last line with the following to achieve it: