在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
PHP拆分金额
<?php function get_money($money,$number,$cash){ $list = array(); for ($i=0; $i < $number - 1; $i++) { $list[] = sprintf("%.2f",$money / 2 * (rand(97,99) / 100) ); } $sum = array_sum($list); $list[] = sprintf("%.2f",$money - $sum); // 调整金额不能超过剩余金额 $list = get_price($list,$money,$cash); return $list; } function get_price($list,$money,$cash){ foreach ($list as $key => $value) { if($value > $cash){ $num = (rand(10,999) / 100); $value = $cash - $num; $min = array_search(min($list),$list); $list[$min] = $list[$min] + $num; $list[$key] = $value; } } $min = array_search(min($list),$list); $sum = array_sum($list); $list[$min] = $list[$min] + ($money - $sum); foreach ($list as $key => $value) { if($value > $cash){ $list = get_price($list,$money,$cash);break; } } return $list; }
|
2022-07-18
2022-08-16
2022-11-06
2022-08-18
2022-08-15
请发表评论