<?php /** * */ //创建1-33的红球数组 $red = range(1,33); //随机取出6个红球 $temp = array_rand($red,6); //由小到大的 //打乱红球的顺序 shuffle($temp); // print_r($temp); Array ( [0] => 6 [1] => 26 [2] => 18 [3] => 4 [4] => 24 [5] => 15 ) //给取出的数字加前导0 foreach ($temp as $v) { $redBall []= $red[$v]>=10?$red[$v]:'0'.$red[$v]; } // print_r($redBall); // 生成随机蓝球 $blue = mt_rand(1,16); // 给蓝球加前导零 $blueBall = $blue>=10?$blue:'0'.$blue; ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div> <div> <div> <h2 >双色球摇奖</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <div> <?php foreach ($redBall as $key => $value) { echo "<span style='color:red'>{$value} </span>"; } echo "<span style='color:blue'>{$blueBall} </span>"; ?> </div> <br> <button type="submit">开奖</button> </form> </div> </div> </div> </body> </html>