Jump to content

$GLOBALS array issue - probably simple solution!


cptn_spoon

Recommended Posts

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:

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

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

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

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!
Link to comment
Share on other sites

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:

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

Then added in the $values array into the UL.

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

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

Thanks anyways everyone!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.