Blogger Information
Blog 61
fans 0
comment 0
visits 62894
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组,随机数
Pengsir
Original
837 people have browsed it

实现步骤:

1、生成6个无序的1-33之间的随机数作为红球

2、生成一个1-16之间的随机数作为蓝球

3、设置开奖按钮,刷新页面。

<?php
/*
 * 双色球
 */
//1.创建1-33个红球区数组
$red_ball=range(1,33);
//2.随机从红球中取6个
$temp=array_rand($red_ball,6);
//3.打乱顺序
shuffle($temp);
//4.给10以下的球号前面加0
foreach ($temp as $i){
    $red[]=$red_ball[$i]<10? ('0'.$red_ball[$i]) :$red_ball[$i];
}
//随机产生一个1到16之间的整数
$blue_ball=mt_rand(1,16);
//蓝球只有一位时也要补0,因为只会有一个蓝球,所以不用循环
$blue = $blue_ball<10 ?('0'.$blue_ball) : $blue_ball;
echo '<div style="width: 45%;height:50px;background: yellow;text-align: center;font-size:2em;font-weight: bolder">';
//输出中奖号码
foreach ($red as $value) {
    echo "<span style='color:red'>{$value}&nbsp;&nbsp;</span>";
}
echo "<span style='color: blue;font-size: 24px;font-weight: bolder;'>$blue_ball</span><br><br>";
echo '<button onclick="window.location.reload()" style="width: 20%">开奖</button>';
echo '</div>';

效果图:

双色球效果图.png

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post