Jump to content

[SOLVED] Dilemna with Arrays


Roybot06

Recommended Posts

Okay I am creating an page using a .php array to randomize a few ads on the page. Every time it is refreshed it will either mix the three ads on the page or throw in another one. I had the idea of linking these pictures to their respective sites, but if I used an anchor tag out side the :

print "<a href=\"#"><img src=\"images/".$ad_array[0]."_120x60.jpg\"></a><br><br>\n";

 

It will give me a fixed link, but I won't have a way of having the link move with the randomizing of the pictures. I was thinking on the lines of creating another array to move with the random pictures.

 

I have the array set to present a word in front of the picture extension (i.e., "red" in the array will make the picture red_120x60.jpg, etc.) , and the array's code:

 

$ad_array = array("red", "green", "blue", "magenta");

 

Does anyone have any suggestions, or can they tell me if what I'm thinking of is possible?

 

Either one will be greatly valued.

 

Thanks

 

 

 

Link to comment
Share on other sites

I tried that, but I need them to randomize in sync.

 

And I can't figure a way to tell the array to place a specific method or tag somewhere...do arrays only take a character string or can I tell it to take the "<a href =\"#"> and move it with the pictures?

Link to comment
Share on other sites

I don't understand your response but a multidimensional array will work.

 

$arr = Array();

$arr[] = Array("www.thisisaurl.com", "thisisanimage.jpg");

 

So then you randomly select an index between 0 and the maximum number of array elements - 1. At this index you do this:

 

$url = $arr[$randomlyselectedindexhere][0];

$img = $arr[$randomlyselectedindexhere][1];

 

You've now got your add and it's associated link.

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.