tsilenzio Posted January 3, 2008 Share Posted January 3, 2008 This works by using nested arrays.. Step One: Fill an array with links. As for the key, give it the name u want the link to say Step Two: Take all the arrays and put them inside a single array. Yet again name the keys for each array the name u want to call the group Note: Code and Preview below.. <?php function output_array($array) { // Confusing eh? You should try writing it >.> // This will break down an array[should be a link array] // and output the nessesary parts foreach ($array as $key => $data) { if(!is_array($data)) { if($data == (basename($_SERVER["SCRIPT_NAME"]))) { // Uncomment line below to skip the current page from linking to itself //continue; } if(end($array) == $data) { echo("<tr><td nowrap=\"nowrap\" valign=\"center\" align=\"left\">" . " <a href=\"$data\">$key</a></td></tr></table></p>"); } else { echo("<tr><td nowrap=\"nowrap\" valign=\"center\" align=\"left\">" . " <a href=\"$data\">$key</a></td></tr>"); } } elseif(is_string($key)) { echo("<p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>" . "<td nowrap=\"nowrap\" valign=\"center\" align=\"left\"><b>$key</b></td></tr>"); output_array($data); } else { output_array($data); } } } $links = array( 'Navigation' => array( 'News' => 'news.php', 'Login' => 'login.php', 'Register' => 'register.php', 'Lost Password' => 'lostpass.php', 'Term of Service' => 'tos.php', 'Contact Us' => 'contact.php', 'About' => 'about.php' ) ); output_array($links); ?> Output: Note: Your results WILL vary from my image, I have taken out a few parts since I took the image as you will see if you use the code. Link to comment https://forums.phpfreaks.com/topic/84246-unusual-link-approach-goodbadimprovments/ Share on other sites More sharing options...
GingerRobot Posted January 3, 2008 Share Posted January 3, 2008 One thing i would notice is that it doesn't appear to give you the functionality of having say, Contact Us lead to contactus.php AND to have Contact Us as an array with sub links such as FAQs, Email Us etc which is quite commonly used on menus. Link to comment https://forums.phpfreaks.com/topic/84246-unusual-link-approach-goodbadimprovments/#findComment-429118 Share on other sites More sharing options...
tsilenzio Posted January 3, 2008 Author Share Posted January 3, 2008 lol my thing was a sample you could add a whole category for Contact Us, just gotta use the array right =] Link to comment https://forums.phpfreaks.com/topic/84246-unusual-link-approach-goodbadimprovments/#findComment-429360 Share on other sites More sharing options...
GingerRobot Posted January 3, 2008 Share Posted January 3, 2008 You misunderstand me. What happens if I want contact us to be a heading AND a link? Link to comment https://forums.phpfreaks.com/topic/84246-unusual-link-approach-goodbadimprovments/#findComment-429599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.