It’s pretty common to want to rotate between ad’s or content. You may want to have a mix of adsense and some CPM, or you may just want to swap between a picture of yourself and a tree.
Here is a neat little switch statement that will allow you to rotate an ad/content every time the page is refreshed:
//rand returns a number between 0 and 2 inclusive
$choice = rand(0, 2);
switch ($choice) {
case 0:
//show adsense
break;
case 1:
//show cpm ad
break;
case 2:
//show a charity banner
break;
}//close switch braces
?>
The script is pretty self explanatory, but if you wanted to increase or decrease the number of ads to rotate through you simply change the variables in the rand function and add or remove new cases.
Thank you for sharing this tip! I’m excited to try this to the website I’m trying to cook up. Wish me luck!
I also enjoy cooking