Need help with looping an array in PHP

Fahrvergnuugen

I am the law!
Alright, its a bit more complex than just looping an array ;)

Here's an array I have:

Code:
	[28] => Jobs/
	[29] => Jobs/GT-30074/
	[30] => Jobs/GT-30074/Engineering/
	[35] => Jobs/GT-30074/Marketing/
	[36] => Jobs/GT-30074/Order Book/
	[37] => Jobs/GT-30074/Service/
	[79] => Jobs/TEST COPY/
	[82] => Jobs/TEST COPY/Engineering/
	[96] => Jobs/TEST COPY/Marketing/
	[80] => Jobs/TEST COPY/Order Book/
	[81] => Jobs/TEST COPY/Service/
As you can see, its an array keyed by a numeric ID (which corresponds to a record in a DB) and its values are file paths.

I want to take that array and put it into an HTML list structure, like this:
Code:
<ul>
	<li>28 jobs
	
	<ul>
		<li>29 GT-30074
		
		<ul>
			<li>30 Engineering
			<li>35 Marketing
			<li>36 Order Book
			<li>37 Service
		</ul>
	</ul>
	
	<ul>
		<li>79 TEST COPY
		
		<ul>
			<li>82 Engineering
			<li>96 Marketing
			<li>80 Order Book
			<li>81 Service
		</ul>
	</ul>
</ul>

The IDs are structured in the same manner as the file paths. It seems simple, until you try to actually do it.
Anybody have any brainy ideas?
 
I was going about this all wrong. I deleted everything that I had tried and started fresh and came up with a solution.

My original approach was to create a multidimensional array of the keys which mimicked the directory structure represented by the paths.

instead I approached it similar to the way XML parsing works with open tag close tag. I kept track of how many slashes I had, if it was more than the last one, then I print a <ul> if its less than I print a </ul>

works like a champ.

Its amazing how simple problems can become if you force yourself to take a break from it :)
 
Back
Top