如何用PHP制作有奖品(数量)的转盘抽奖?

如何用PHP制作有奖品(数量)的转盘抽奖?,第1张

这个不是有key值么,抽到后把这个key值的给unset()

unset() 方哗姿枝法

注意如果你使用 unset() 方法,它是册凯不会改变其他的键(key),如果你想对其他的键(key)重新整理排序,可以使用 array_values()。

<?php

$array = array(0 =>"a", 1 =>"b", 2 =>"c")unset($array[1])

//↑ 你要删除的数组元素值的键乱敏print_r($array)?>

输出结果:

Array (

[0] =>a[2] =>c)

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

代码如下:

<?php

/**

*

抽奖

*

@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<$win1$i++)

{

$return[]

=

1

}

for

($j=0$j<$win2$j++)

{

$return[]

=

2

}

for

($m=0$m<$win3$m++)

{

$return[]

=

3

}

for

($n=0$n<$other$n++)

{

$return[]

=

'谢谢惠顾'

}

shuffle($return)

return

$return[array_rand($return)]

}

$data

=

getReward()

echo

$data

?>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12364121.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存