Sep 12 2006

Creating a rotating ad in PHP

First open up your up a file in your text editor of choice. In this example I’m going to call the file ad.php and just include it in the page I wish for it to show up in.

Second I’ll define my ads:

<?php
$ad[1] = "We got the goods here";
$ad[2] = "Give us your money";
$ad[3] = "blah blah blah";

Now that you’ve got an array defined for your ads we will use rand() to call them up randomly:


$random = rand(1, sizeof($ad));
echo $ad[$random];
?>

That’s it. Hope this is helpful.