NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 Hello there, I'm trying to make a addon(future) for one of my applications. Basically what I'm trying to do is to be able to add extra links to a navigation tab. At the end I want to only have one variable(array) with all the data in an array. And then Send the data to the navigation function to add the extra links. I Could simply run trough it with a foreach loop, When I thought about it I hit a Wall. ~| I just can't think of how to use a loop to get the data and echo it in links. I'm thinking of doing something like the following, $Links = array( "Tab Name" => array( "Link One" => "index.php", "Link Two" => "apps.php") ), "Tab Two" => array( "Link Three" => "info.php") ); Okay.., Simple enough to create an array.. Here is my question, How would I go about extracting the data out of the array, and display them? Should I just make another two variables, and again, and again..? I think If I did that the script would time out. The Output must look similar to this example: <u>Tab One</u> <br /> <a href="index.php">Link One</a><br /> <a href="apps.php">Link Two</a><br /> <br /> <u>Tab Two</u> <br /> <a href="info.php">Link Three</a><br /> Can Someone explain to me how I could do this? I would also be thankful if I could get an example on how to do this. Thanks.. Ferdi Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 14, 2007 Share Posted August 14, 2007 if only you had taken a modular approach to your app..... what you are asking has a number of solutions - basically whereever you have your nav - if ist already in an array then you could simply append these new links you want. Alternatively you could re-use your code that creates the navigation list to create another with these new links... with the code you have (I assume you use a foreach loop to traverse the array) you simply need to nest that foreach in another one that will loop through the keys of the 'parent' array. Quote Link to comment Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Author Share Posted August 14, 2007 Shht... Bit of what they call a blond moment.. <?php $Links = array( 'Tab Name' => array( 'Link One' => 'index.php', 'Link Two' => 'apps.php', ), 'Tab Two' => array( 'Link Three' => 'info.php') ); foreach($Links as $Tabs => $Number){ Echo $Tabs. '<br />'; foreach ($Number as $Links => $Tittle){ Echo '<a href="' . $Tittle . '">'. $Links . '</a><br />'; } Echo '<br />'; } ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 15, 2007 Share Posted August 15, 2007 Congratulations - a 5 gallon bottle of peroxide is winging its way to your door.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.