www.webdeveloper.com
Results 1 to 2 of 2

Thread: Multidimensional Nav Array

  1. #1
    Join Date
    Jun 2003
    Posts
    34

    Multidimensional Nav Array

    Hi. Can someone help me set up an array for a file I am using in navigation? The navigation is an unordered list, which will then get styled as tabs with CSS.

    It needs to store 6 things.
    1) The name of the link
    2) The URL of each link
    3) A sub link name, if there is one
    4) The sub nav's URL

    It should generate something like this:
    Code:
    <ul id="primary">
    <li><a href="main.html">Main Item 1</a></li>
    <li><a href="main2.html">Main Item 2</a>
    <ul id="secondary">
    <li><a href="subnav">Sub</a></li>
    </ul>
    </li>
    </ul>
    Anyway a one dimensional array is easy. that would be this:
    Code:
    <?php
    $nav_items = array(
    "Home" => "index.php",
    "Resources" => "resources.php",
    "Help" => "help.php",
    "About NCBI" => "about.php"
    );
    
    echo "<ul id=\"primary\">\n";
    foreach ($nav_items as $txt => $url) { 
       echo "\t<li><a href=\"$url\">$txt</a></li>\n";
    }
    echo "</ul>";
    ?>
    But how would I create an array that would also hold sub nav items and their hrefs?

  2. #2
    Join Date
    May 2004
    Location
    FL
    Posts
    3,453
    Please don't double post. Other thread removed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles