Blogger Information
Blog 14
fans 0
comment 0
visits 12151
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP+Ajax幸运大转盘抽奖实例
alber1986的博客
Original
1329 people have browsed it

222222.png

PHP+Ajax制作的一款幸运大转盘抽奖实例,通过奖品库存、中奖次数来计算中奖概率

奖品设置

$prizes = array( 
        0 => array( 
            "id" => 0, //中奖id 
            "name" => "谢谢参与", //奖品名称 
            "count" => "100", //库存 
        ), 
        1 => array( 
            "id" => 1, 
            "name" => "罗浮山门票", 
            "count" => "40", 
        ), 
        2 => array( 
            "id" => 2, 
            "name" => "罗浮山嘉宝田温泉体验券", 
            "count" => "40", 
        ), 
        3 => array( 
            "id" => 3, 
            "name" => "精美旅游书籍《山水酿惠州》", 
            "count" => "40", 
        ), 
        4 => array( 
            "id" => 4, 
            "name" => "碧海湾漂流门票", 
            "count" => "40", 
        ), 
        5 => array( 
            "id" => 5, 
            "name" => "南昆山门票", 
            "count" => "40", 
        ), 
        6 => array( 
            "id" => 6, 
            "name" => "云顶温泉精美礼品", 
            "count" => "40", 
        ), 
    );

获取中奖概率,若是库存为0的则不计算

function getRand($proArr, $proCount) { 
    $result = ''; 
    $proSum = 0; 
    foreach ($proCount as $key => $val) { 
        if ($val <= 0) { 
            continue; 
        } else { 
            $proSum = $proSum + $proArr[$key]; 
        } 
    } 
    foreach ($proArr as $key => $proCur) { 
        if ($proCount[$key] <= 0) { 
            continue; 
        } else { 
            $randNum = mt_rand(1, $proSum); 
            if ($randNum <= $proCur) { 
                $result = $key; 
                break; 
            } else { 
                $proSum -= $proCur; 
            } 
        } 
    } 
    unset($proArr); 
    return $result; 
}

本实例下载:https://www.sucaihuo.com/php/3301.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