PHP implements lucky red envelope function

PHP中文网
Release: 2023-03-15 17:30:02
Original
1954 people have browsed it

/** * php拼手气红包函数 * @param int $fee 红包总金额 * @param int $c 发给多少人 * @return array */ function RedEnvelope($fee,$c){ $fee = 100; $n = $fee/2; for($i=0;$i<$c;$i++){ if($i==($c-1)){ $arr[]=$fee; }else{ $arr[]=$j=rand(0.01,$n)+rand(11,99)/100; $fee = $fee-$j; $n = $fee/4; } } return $arr; } //使用示例 $arr=RedEnvelope(100,10); print_r($arr); $z =0; foreach($arr as $v){ $z +=$v; echo $v."+"; } echo "=",$z;
Copy after login

PHP implements lucky red envelope function

The above is the detailed content of PHP implements lucky red envelope function. For more information, please follow other related articles on the PHP Chinese website!

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
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!