Everyday, I see lots of people using code looking something like this:
<?php $rand = mt_rand(1,10); if ($rand == 1) {echo 'What ever you want to do if $rand == 1';} elseif ($rand == 2) {echo 'What ever you want to do if $rand == 2';} elseif ($rand == 3) {echo 'What ever you want to do if $rand == 3';} elseif ($rand == 4) {echo 'What ever you want to do if $rand == 4';} elseif ($rand == 5) {echo 'What ever you want to do if $rand == 5';} elseif ($rand == 6) {echo 'What ever you want to do if $rand == 6';} elseif ($rand == 7) {echo 'What ever you want to do if $rand == 7';} elseif ($rand == 8) {echo 'What ever you want to do if $rand == 8';} elseif ($rand == 9) {echo 'What ever you want to do if $rand == 9';} elseif ($rand == 10) {echo 'What ever you want to do if $rand == 10';} ?>
When, surely, it is easier to use the switch command, which will require less code (although more whitespace is common) and will be more readable, it'd look something like this:
<?php $rand = mt_rand(1,10); switch ($rand) { case 1:echo 'What ever you want to do if $rand == 1';break; case 2:echo 'What ever you want to do if $rand == 2';break; case 3:echo 'What ever you want to do if $rand == 3';break; case 4:echo 'What ever you want to do if $rand == 4';break; case 5:echo 'What ever you want to do if $rand == 5';break; case 6:echo 'What ever you want to do if $rand == 6';break; case 7:echo 'What ever you want to do if $rand == 7';break; case 8:echo 'What ever you want to do if $rand == 8';break; case 9:echo 'What ever you want to do if $rand == 9';break; case 10:echo 'What ever you want to do if $rand == 10';break; } ?>
Of course, use of switch is not limited to number generated by the mt_rand command, it's just what I've chosen to use in my example here, partly because I've been using mt_rand quite a lot recently...
Relevent PHP Manual Pages: