In this tutorial Im going to show you how to make a random advert rotator.
The way we are going to do it is through an array to define our adverts then use an array function to shuffle the array.
So the first thing we need to create the array…
$adverts=array('<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'1','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'2','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'3');
Now we have done that we need to make the array show up randomly. We do that using a function called array_rand ( ).
print_r(array_rand($adverts,1));
Then thats everything. Heres a demo that uses my three websites as adverts.
Full Code:
<?php $adverts=array('<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'1','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'2','<a href="http://www.website.com"><img src="image.gif" alt="" /></a>'=>'3'); print_r(array_rand($adverts,1)); ?>






































November 22nd, 2008 at 5:56 pm
Hi! Your Post “” is very interesting for me. Unfortunately my written English is not so good so I write in German: Dir, meinem liebsten, geh