/** * 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