SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with listing array

    Ok so i have a file that im including to each of my pages, the file contains all the things that i need to be on evry page but i may want to change at some point and i might aswell change 1 source rather than dozens. I want to create an array (open to other suggestions) that will contain a list of links that will create my menu. So basically on

    include.php

    PHP Code:
    <?

    $Menu 
    = array('Link1''Link2'); // And so on...

    ?>
    then on each of my pages the page is included but how would i display each of the links as a seperate html line i.e (bearing in mind there could be any number of links and each needs its own line of code, so needs to be fully dynamic)

    PHP Code:
    <class="nav" href="mylinkhere.php">Links</a><span class="hide"> | </span

    I mean i could do it with a DB no problem, but can it be done using an array and an included page?

    Thanks in advance, WebNoob
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm,

    PHP Code:
    <?php

    $menu 
    = array('Home' => 'index.php''Contact' => 'contact.php');//etc

    foreach($menu as $anchor => $link)
    {
      echo 
    '<a class="nav" href="'.$link.'">'.$anchor.'</a><span class="hide"> | </span>';
    }
    ?

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...possibly making it a little more readable(?):
    PHP Code:
    $menu = array('index.php'=>'Home''contact.php'=>'Contact');//etc

    foreach($menu as $href =>$linkText)
    {
        echo<<<UNIQUEID
            <a class="nav" href="$href">$linkText</a>
            <span class="hide"> | </span>
    UNIQUEID;


  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks guys ill give it a go thanks. Is this a good way to do what im aiming for, or is using a DB better off?

    WebNoob
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What SecondIV said should work fine, and I personally think using a DB for this would be overkill.

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah ok then, well ive implemented it now and its worked great, thx very much.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"


Bookmarks

Posting Permissions

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