PHP random ad insertion coding

Discussion in 'PHP' started by versalash, Jan 27, 2012.

  1. #1
    Hello,

    Excuse the improper use of programming terminology, am slowly learning some basics!

    I have a script that has the following code to call some html code in a field and display. There are 9 fields (advert0, advert1, etc).

    <? echo $adexchange[advert0]; ?>

    Instead of always calling advert0 I want it to call a random advert between 0 and 9.

    Is there any way to do this?

    Thanks!
     
    versalash, Jan 27, 2012 IP
  2. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    yes there is. you can use <?php $randAdvert = "advert".rand(0,9); echo $adexchange[$randAdvert];?>
     
    iama_gamer, Jan 27, 2012 IP
  3. versalash

    versalash Greenhorn

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Great, thanks!
     
    versalash, Jan 28, 2012 IP