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
https://forums.phpfreaks.com/topic/64828-solved-array-of-links/
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
https://forums.phpfreaks.com/topic/64828-solved-array-of-links/#findComment-323453
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
https://forums.phpfreaks.com/topic/64828-solved-array-of-links/#findComment-323489
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.