概述
PHP+AJAX开发幸运大转盘抽奖
PHP+AJAX开发幸运大转盘抽奖,通过奖品库存、中奖次数来计算中奖概率
奖品设置
1 $prizes = array( 2 0 => array( 3 "id" => 0, //中奖id 4 "name" => "谢谢参与", //奖品名称 5 "count" => "100", //库存 6 ), 7 1 => array( 8 "id" => 1, 9 "name" => "罗浮山门票", 10 "count" => "40", 11 ), 12 2 => array( 13 "id" => 2, 14 "name" => "罗浮山嘉宝田温泉体验券", 15 "count" => "40", 16 ), 17 3 => array( 18 "id" => 3, 19 "name" => "精美旅游书籍《山水酿惠州》", 20 "count" => "40", 21 ), 22 4 => array( 23 "id" => 4, 24 "name" => "碧海湾漂流门票", 25 "count" => "40", 26 ), 27 5 => array( 28 "id" => 5, 29 "name" => "南昆山门票", 30 "count" => "40", 31 ), 32 6 => array( 33 "id" => 6, 34 "name" => "云顶温泉精美礼品", 35 "count" => "40", 36 ), 37 );
获取中奖概率,若是库存为0的则不计算
1 function getRand($proArr, $proCount) { 2 $result = ''; 3 $proSum = 0; 4 foreach ($proCount as $key => $val) { 5 if ($val <= 0) { 6 continue; 7 } else { 8 $proSum = $proSum + $proArr[$key]; 9 } 10 } 11 foreach ($proArr as $key => $proCur) { 12 if ($proCount[$key] <= 0) { 13 continue; 14 } else { 15 $randNum = mt_rand(1, $proSum); 16 if ($randNum <= $proCur) { 17 $result = $key; 18 break; 19 } else { 20 $proSum -= $proCur; 21 } 22 } 23 } 24 unset($proArr); 25 return $result; 26 }
本文转自:http://www.sucaihuo.com/php/3301.html 转载请注明出处!
posted on
2018-11-05 10:26
llzoyf 阅读(
...) 评论(
...)
编辑
收藏
转载于:https://www.cnblogs.com/llzoyf/p/9907720.html
最后
以上就是开心白昼为你收集整理的PHP+AJAX开发幸运大转盘抽奖的全部内容,希望文章能够帮你解决PHP+AJAX开发幸运大转盘抽奖所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复