Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

foreach in a foreach?

Status
Not open for further replies.

rye8261

Technical User
Jul 6, 2003
359
US
Ok, here is my problem. I have a loop that looks through several folders and then looks in each of those folders to return the names of the subfolders.

I have the first foreach working fine. It will return the names of the folders however I can't figure out how to have it open each of the folders and place the folders in that folder into a string.

Ex. folder structure

Theme1
Sub-Theme1
Sub-Theme1.2
Theme2
Sub-Theme2
Theme3
Sub-Theme3
Sub-Theme3.2

What I'd like to do is display like this on my webpage:
Theme1 - Sub-Theme1, SubTheme1.2
Theme2 - Sub-Theme2
Theme3 - Sut... You get the picture.




---------------------------------------
- Free General Web Directory, Free Web site submissions.
- Free General Web Directory, Free Web site submissions.
 
Use the same format as you are using for the parent folder names but process the child folders instead.
It may help provide a solution if you show the code you have already.


Keith
 
something like this: (note this is from one of my projects, just replace with your own values) and you can keep making arrays within arrays, just keep adding a foreach statement inside another one.

Code:
$menu = array(
"roster" => array('insert', 'add player', 'delete player', 'view'),
"lineup" => array('make'),
"gameaction" => array('defense', 'offense', 'pitching'),
"other" => array('viewbook', 'pitchaction', 'spraychart', 'playtime'));

echo '<table border="1">';

foreach ($menu as $key1 => $insidearray) { echo '<tr><td><b>'.$key1.' - </b></td>'; 
   foreach ($insidearray as $value2) 
{echo '<td><a href="'.$value2.'.php">'.$value2.'</a>,</td>'; }
echo '</tr>'; }
echo '</table>';

Thats the basic concept of it, you can also add specific keys too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top