Home > php教程 > php手册 > body text

php实现可以设置中奖概率的抽奖程序代码分享

WBOY
Release: 2016-06-06 20:25:29
Original
922 people have browsed it

这篇文章主要介绍了一个抽奖程序,要求一等奖的中奖概率是0.12%,二等奖中奖概率是3%,三等奖中奖概率是12%,其他中奖概率是都是谢谢惠顾

复制代码 代码如下:


/**
 * 抽奖
 * @param int $total
 */
function getReward($total=1000)
{
 $win1 = floor((0.12*$total)/100);
 $win2 = floor((3*$total)/100);
 $win3 = floor((12*$total)/100);
 $other = $total-$win1-$win2-$win3;
 $return = array();
 for ($i=0;$i {
  $return[] = 1;
 }
 for ($j=0;$j {
  $return[] = 2;
 }
 for ($m=0;$m {
  $return[] = 3;
 }
 for ($n=0;$n {
  $return[] = '谢谢惠顾';
 }
 shuffle($return);
 return $return[array_rand($return)];
}

$data = getReward();
echo $data;
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!