function getRand($proArr, $proCount) {

$result = '';

$proSum = 0;

php大转盘原理PHP新写的年夜转盘抽奖源码 React

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\"大众,

),

);

源码来源:https://gitee.com/lanrenzhijia/codes/d342lk1yw5nm8x09euqag50