Jump to content

Unusual Link Approach Good/Bad/Improvments?


tsilenzio

Recommended Posts

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:

navuf3.png

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

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.

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.