No more nonsense, all the explanations are in the code, as shown in the code below:
/*** @param $total [Amount of red envelopes you want to send]* @param int $num [send several]* @return array[generate red Envelope amount]*/function getredgift ($total, $num = ten) {$min = 0.01; $wamp = Array (); $returnData = Array (); for ($i = 1; $i < $num; + + $i) {$safe _total = ($total-($num-$i) * $min) /($num-$i); Maximum amount of red envelopes if ($safe _total < 0) break; $money = @mt_rand ($min *, $safe _total * 100)/100;//randomly generates a red envelope amount $total = $total -$money;//Total bonus $wamp[$i] = round ($money, 2);//reserved two valid digits} $wamp [$i] = Round ($total, 2); $returnData [' moneysum '] = $wamp; $ returndata[' newtotal ' = Array_sum ($wamp); return $returnData;} Test $data = Getredgift (1),;p Rint_r ($data);//result:/*array ([] = 8.7[2] [10.09[3] = 6.23[4] = 6.87[ 5] [= 0.47[6] = 3.12[7] = 7.52[8] = 12.21[9] = 20.53[10] = 24.26) */
Code to this to everyone has finished, hope to help! More about PHP generated red Envelopes program code in the site, please visit our website to learn more information, thank you!
The above describes the PHP generated red envelope code is simple, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.