Home > Backend Development > PHP Tutorial > http://www.12306.cn/mormhweb/ php - Generate coupon code

http://www.12306.cn/mormhweb/ php - Generate coupon code

WBOY
Release: 2016-07-29 08:42:09
Original
1126 people have browsed it

/*
* Generate coupon code
* $nums How many coupon codes are generated
* $codelength Coupon code length
* $format Coupon code prefix name (not included in the coupon code length)
* $type Return type json array
* /
function get_code($nums = 6 ,$codelength = 6 ,$format = '' ,$type = 'array' )
{
$mcode = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$mcode_len = strlen($ mcode);
$ rs = array();
for($i=0;$i<$nums;)
                                                                
                $str_len = rand(0,$mcode_len-1);         $d = in_array($code,$ rs);
                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                        having returning $rs;
              return json_encode($rs);

}

#For debugging


function pc($data)

{

                                                             echo '

 ';

                                                                                                                                                                                                                                                                            print_r(


}

}


pc(get_code ());

pc(get_code(10,10,'-N','json'));

#If you have any problems with the code you wrote, please contact me and I will modify it

The above introduces http://www.12306.cn/mormhweb/ php - generate coupon code, including the content of http://www.12306.cn/mormhweb/. I hope friends who are interested in PHP tutorials can learn from it. help.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template