outputting multi-dim array

I'm building a nav structure in PHP that's using simplified XML files
to populate an unordered list. I have an xml parser that coverts my XML
to a multi-dimensional array, but I'm having issues getting by data out
of that array.

My xml file looks something like this:

<SECTION title="Search Engines">
<ITEM name="Google" url="www.google.com" />
<ITEM name="Yahoo" url="www.yahoo.com" />
</SECTION>
<SECTION title="Boogers">
<ITEM name="Slimy" url="slimy.com" />
<ITEM name="Crunchy" url="crunchy.com" />
</SECTION>

I'm very used to using a for loop over single-dim arrays but not so
much on mult-dim arrays. I'd like to output something like this:

<li class="title">Search Engines</li>
<li>Google</li>
<li>Yahoo</li>
<li class="title">Boogers</li>
<li>Slimy</li>
<li>Crunchy</li>

I've been looking at examples and pouring over php.net's docs to no
avail, and can't seem to get a loop structure that'll output what seems
like a very simple multi-dim array structure.
Can anyone point me in the right direction for that loop, or suggest a
better way for me to go about this?
Decavolt [ Do, 25 Januar 2007 18:19 ] [ ID #1608128 ]

Re: outputting multi-dim array

Decavolt wrote:

> I'm very used to using a for loop over single-dim arrays but not so
> much on mult-dim arrays. I'd like to output something like this:

Usually you add a for loop for each dimention

for($i=0;$i<count($array);$i++) {
//do what you need to do for first - Search Engines, Boogers
echo $array[$i];
for($j=0;$j<count($array[$i]);$j++) {
//do what you need to do for second Google,Yahoo+Slimy,Crunchy
echo $array[$i][$j];
}
}

--

//Aho
Shion [ Do, 25 Januar 2007 19:03 ] [ ID #1608129 ]
PHP » alt.php » outputting multi-dim array

Vorheriges Thema: Binary-safe?
Nächstes Thema: Http_output