三項演算子で、条件判定し、trueならぞろ目と表示させています。
<?php $dice = mt_rand(1, 6); $dice2 = mt_rand(1, 6); $zorome = ($dice == $dice2) ? true: false; ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>さいころ</title> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> </head> <body> <h1>サイコロ</h1> <p>サイコロの目は「<?php echo $dice; ?>」と「<?php echo $dice2; ?>」でした!</p> <?php if ($zorome == true): ?> ぞろ目です! <?php endif; ?> <p><a href="<?php echo $_SERVER["SCRIPT_NAME"]; ?>">もう一度!</a></p> </body> </html>
mt_rand()はrand()より、4倍処理が速いとphpのドキュメントに記載があります。
php mt_rand()
/*
Many random number generators of older libcs have dubious or unknown characteristics and are slow. By default, PHP uses the libc random number generator with the rand() function. The mt_rand() function is a drop-in replacement for this. It uses a random number generator with known characteristics using the » Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.
*/