This paper gives an example of how to implement the algorithm of PHP imitation micro-letter red envelope assignment. Share to everyone for your reference, specific as follows:
/**
* Bonus allocation: Assign a certain amount randomly to a specified number *
* @param int $money The amount to be allocated
* @param int $num assigned number * *
function Randommoney ($money, $num) {
echo "$money element is randomly divided into $num parts respectively is:<br/>";
$remain = $money;
$use =0;
for ($i =1; $i < $num; $i + +) {
$temp =rand (0, $remain *100)/100;
echo "Balance:". $remain. ", used:". $use. ", Assigned:". $temp. " <br/> ";
$use + + $temp;
$remain-= $temp;
}
echo "Balance:". $remain. ", used:". $use. ", assigning:". $remain;
}
echo Randommoney (10,5);
PS: Small knitting here recommend a site for the layout of the PHP format landscaping tools to help you in the future of PHP programming code layout:
PHP Code online Format Landscaping tool:Http://tools.jb51.net/code/phpformat
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.