Hello, I have used the following php script to get random text in my website... <?php $number=mt_rand(1, 6); if ($number=="1") { include "navrandom1.php"; } if ($number=="2") { include "navrandom2.php"; } if ($number=="3") { include "navrandom3.php"; } if ($number=="4") { include "navrandom4.php"; } if ($number=="5") { include "navrandom5.php"; } if ($number=="6") { include "navrandom6.php"; } ?> HTML: ... each .php page is simply a paragraph and it works just fine, however, I was hoping to add about 20 different items as oppose to the current 6. Is there a shortcut in doing this or do I have to put... [HTML]<?php if ($number=="?") { include "navrandom?.php"; } HTML: for each single item. Also, is there a way to put all the paragraphs in one page and have the script randomly choose one paragraph to display?
You could use arrays. $paragraphs = array( '<p>Paragraph 1</p>', '<p>Paragraph 2</p>', '<p>Paragraph 3</p>', '<p>Paragraph 4</p>', ); $random = $paragraphs[array_rand($paragraphs)]; echo $random; PHP: