PHP Generate coupon Activation code

Source: Internet
Author: User

/** * Generate VIP Activation code * @param int $nums How many coupon codes * @param array $exist _array exclude the coupon code in the specified array * @pa Ram int $code _length The length of the coupon code * @param int $prefix generate the specified prefix * @return array returns excellent Array of Megumi codes*/     Public functionGeneratecode ($nums,$exist _array= ",$code _length= 6,$prefix= ' ' ) {            $characters= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNPQRSTUVWXYZ"; $promotion _codes=Array();//This array is used to receive the generated coupon code             for($j= 0;$j<$nums;$j++) {                            $code= ' ';  for($i= 0;$i<$code _length;$i++) {                    $code.=$characters[Mt_rand(0,strlen($characters)-1)]; }                            //if the generated 4-bit random number is no longer within the $promotion_codes array we define            if( !In_array($code,$promotion _codes) ) {                    if(Is_array($exist _array) ) {                                            if( !In_array($code,$exist _array) ) {//exclude a coupon code that has been used                            $promotion _codes[$j] =$prefix.$code;//assign the generated new coupon code to the Promotion_codes array                        } Else {                            $j--; }                                        } Else {                                            $promotion _codes[$j] =$prefix.$code;//assign a coupon code to an array                                        }                } Else {                $j--; }        }            return $promotion _codes; }

PHP Generate coupon Activation code

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.