Hello everyone, I'm looking for (what should be) a simple PHP script. I'm fairly sure you're all familar with the "random quote" script that can be done, however can a similar thing be done with printing code on a web page? For example, say I have the following bits of code: <div class="red">This is red square</div> Code (markup): <div class="green">This is a green square</div> Code (markup): <div class="blue">This is a blue square</div> Code (markup): ...so, how could I use PHP to make those appear randomly each time the page is refreshed or reloaded? Thanks very much, and I'm happy to answer questions.
<?php $random_num = rand(1,3); // selects random number between 1 and 3 switch ($random_num) { case 1: echo "<div class=\"red\">This is red square</div>"; break; case 2: echo "<div class=\"green\">This is a green square</div>"; break; case 3: echo "<div class=\"blue\">This is a blue square</div>"; break; } ?> PHP: