码迷,mamicode.com
首页 > Web开发 > 详细

PHP新写的大转盘抽奖源码

时间:2018-12-30 17:33:40      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:抽奖   function   foreach   array   体验   roc   中奖概率   tran   http   


中奖概率


抽奖大转盘演示:http://www.sucaihuo.com/php/3301.html
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; 
}


奖品设置


$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", 
        ), 
    );
    

PHP新写的大转盘抽奖源码

标签:抽奖   function   foreach   array   体验   roc   中奖概率   tran   http   

原文地址:https://www.cnblogs.com/qixidi/p/10199688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!