Jump to content

[SOLVED] Array of links.


NArc0t1c

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 />';
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.