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