Blogger Information
Blog 33
fans 0
comment 2
visits 41924
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 数组实例-双色球开奖
hanyufeng的博客
Original
1135 people have browsed it

运行效果:

双色球开奖.gif

说明:

产生顺序数组,再从中随机选出6个红球。

再另外产生一个随机数,作为蓝球。

示例源码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .c-icon-ball-blue {
            background-position: -48px -240px;
 }

        .op_caipiao_ball_blue {
            color: #39f;
 }

        .c-icon-ball-blue, .c-icon-ball-red {
            width: 38px;
 height: 38px;
 }
        .op_caipiao_ball {
            margin-right: 20px;
 }

        .c-gap-bottom {
            margin-bottom: 10px;
 }
        .c-gap-top {
            margin-top: 10px;
 }
        .c-clearfix {
            zoom: 1;
 }

        .c-border .c-gap-right-small {
            margin-right: 5px;
 }
        .op_caipiao_ball span {
            line-height: 38px;
 vertical-align: middle;
 font-size: 20px;
 text-align: center;
 }
        .op_caipiao_ball_red {
            color: #f54646;
 }
        .c-icon-ball-red {
            background-position: 0 -240px;
 }
        .c-icon-ball-blue, .c-icon-ball-red {
            width: 38px;
 height: 38px;
 }
        .c-icon {
            display: inline-block;
 width: 38px;
 height: 38px;
 vertical-align: text-bottom;
 font-style: normal;
 overflow: hidden;
 }        
 .c-icon {
            background-image: url(https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png);
 }

        .c-gap-right-small {
            margin-right: 6px;
 }

    </style>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-12 text-center">
            <h3>双色球</h3>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-center">
            <div class="c-gap-top c-gap-bottom op_caipiao_ball c-clearfix">
                <?php
 /**
                 * Created by PhpStorm.
                 * User: Administrator
                 * Date: 2018/1/8
                 * Time: 19:36
                 * 双色球
 */

                //创建 1-33红球区数组
 $red_ball = range(1,33);
 //随机从红球中取出6个
 $temp = array_rand($red_ball,6);

 //打乱顺序
 shuffle($temp);

 foreach ($temp as $i ){
                    //当红球为个位数时,前面补一个前导0,最后生成的红球保存在数组$red中
 $red_result[] = $red_ball[$i]<10?('0'.$red_ball[$i]) : $red_ball[$i];
 }
                //随机产生一个1到16之间的整数
 $blue_ball = mt_rand(1,16);
 //当蓝球为个位数时,前面补一个前导0
 $blue_result = $blue_ball<10 ?('0'.$blue_ball) : $blue_ball;
 //输出中奖号码
 foreach ($red_result as $value) {
                    echo '<span class="c-icon c-icon-ball-red op_caipiao_ball_red c-gap-right-small">'.$value.'</span>';
 }
                echo '<span class="c-icon c-icon-ball-blue op_caipiao_ball_blue c-gap-right-small">'.$blue_result.'</span>';
 ?>

 </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-center">
            <form action="" method="post">
                <button id="submit" class="btn btn-primary">开奖</button>
            </form>

        </div>
    </div>
</div>


</body>
</html>


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!