<?php
$prizes = [0 => ['jine' => 100, 'luck' => 10],
1 => ['jine' => 80, 'luck' => 20],
2 => ['jine' => 60, 'luck' => 40],
3 => ['jine' => 40, 'luck' => 60],
4 => ['jine' => 20, 'luck' => 80],
5 => ['jine' => 10, 'luck' => 100],
6 => ['jine' => 5, 'luck' => 120]];
$zjnumber = array_sum(array_column($prizes, 'luck'));
//获得中奖值
$zjhm = rand(1, $zjnumber);
//奖品信息
$zjxx = "";
//中奖几率
$zjjl = 0;
foreach ($prizes as $vo) {
$zjjl += $vo['luck'];
if ($zjjl > $zjhm) {
$zjxx = $vo;
break;
}
}
echo $zjhm;
print_r('恭喜中奖' . $zjxx['jine'] . '这个奖品的中奖几率是' . $zjnumber . '分之' . $zjxx['luck']);
?>
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询