PHP: simple code for generating WeChat red packets, php code for generating red packets _ PHP Tutorial

Source: Internet
Author: User
PHP generates the red envelope code easily. php generates the red envelope code. PHP's red envelope generation code is simple. php's red envelope generation code is not much nonsense. all explanations are in the code. the specific code is as follows: * ** @ param $ total [the total amount of red packets you want to send. The PHP code for generating red packets is simple. The php code for generating red packets

The code is as follows:

/*** @ Param $ total [total red envelopes you want to send] * @ param int $ num [send a few] * @ return array [generate red envelope amount] */function getRedGift ($ total, $ num = 10) {$ min = 0.01; $ wamp = array (); $ returnData = array (); for ($ I = 1; $ I <$ num; + + $ I) {$ safe_total = ($ total-($ num-$ I) * $ min)/($ num-$ I ); // if ($ safe_total <0) break; $ money = @ mt_rand ($ min * 100, $ safe_total * 100)/100; // Generate a random red packet amount $ total = $ total-$ money; // total remaining red packets $ wamp [$ I] = round ($ money, 2 ); // retain two valid numbers} $ wamp [$ I] = round ($ total, 2); $ returnData ['moneysum'] = $ wamp; $ returnData ['newtotal'] = array_sum ($ wamp); return $ returnData;} // test $ data = getRedGift (100, 10); print_r ($ data ); // result: /* Array ([1] => 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) */

The code has been written here, and I hope it will help you! For more program code about generating red packets in php, visit our official website to learn more. thank you!

Articles you may be interested in:
  • PHP public platform red envelope API
  • Use PHP to write a red envelope program
  • PHP implements the red packet sending program
  • Code sharing of the random amount of red packets generated by jquery + php
  • Analysis of the red envelope algorithm implemented by php (unofficial)
  • PHP red packet API interface
  • Official php interface (payment, red envelopes, shake, store)
  • Use PHP to shake the surrounding red envelope

Http://www.bkjia.com/PHPjc/1113694.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1113694.htmlTechArticlePHP generate red envelope code is simple, php generate red envelope code nonsense not much said, all explanations in the code, the specific code is as follows: /*** @ param $ total [total amount of red packets you want to send...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.