Jump to content


Photo

$GLOBALS array issue - probably simple solution!


  • Please log in to reply
1 reply to this topic

#1 cptn_spoon

cptn_spoon
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 20 April 2006 - 06:54 AM

Hi all,

I have run into a problem that for the life of me I can't think of a logical answer to even though I'm sure it is really simple!

I am storing some values in a $GLOBALs array as follows:

$GLOBALS['links']=array("Link1","Link2","Link3");
$GLOBALS['linksAnchor']=array("$GLOBALS['directory']","$GLOBALS['directory']/link2","$GLOBALS['directory']/link2/link3");

Then at another time I'm calling them as follows:

<ul>
    <?
    foreach($GLOBALS['links'] as $value){ 
    ?>
        <li><?=$value?></li>
    <?
    }
    ?>
</ul>

Now I want those <li>'s to contain <a>'s linking to the links provided in the second array. I was thinking of using a hash table of sorts (dictionary, whatever you call them) but then I don't know how to pull both values out in that kind of order.

Please help me here it's driving me crazy! If you need any further clarification on what I'm trying to achieve please just ask.

Thanks in advance!

#2 cptn_spoon

cptn_spoon
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 20 April 2006 - 09:59 AM

Well fine people don't help! :P

No no, its all good! I just figured it out myself. So in case anyone Googles onto this, here's the solution:

I nested arrays within the original:

$GLOBALS['links']=array(array("Link1","http://link1"),array("Link2","http://link2"),array("Link3","http://link3"));

Then added in the $values array into the UL.

<ul>
    <?
    foreach($GLOBALS['links'] as $value){
    ?>
          <li><a href="<?=$value[1]?>"><?=$value[0]?></a></li>    <?
    }
    ?>
</ul>

Simple! I did say it was probably simple! :P

Thanks anyways everyone!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users