So we know that simple four-digit pure digital verification in PHP can be done with Rand (1000,9999), but if we're going to get a random four-digit number of letters and numbers, how do we write a function? The following Hu Peng blog in the PHP data column gives a complete example.
<?php
function Getfourstr ($len)
{
$chars _array = Array (
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9 ","
a "," B "," C "," D "," E "," F "," G "," H "," I "," J "," K ","
L "," M "," N "," O "," P "," Q "," R "," s "," T "," U "," V ",
"W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F", "G", "
H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
" S "," T "," U "," V "," W "," X "," Y "," Z ",
);
$charsLen = count ($chars _array)-1;
$outputstr = "";
for ($i =0; $i < $len; $i + +)
{
$outputstr. = $chars _array[mt_rand (0, $charsLen)];
}
return $outputstr;
}
Echo Getfourstr (4);
? >
Part of the function parsing: mt_rand function Description: Mt_rand () returns a random integer.
If the optional parameter min and Max,mt_rand () are not provided, the pseudo random number between 0 and Rand_max is returned. For example, want a random number between 0 and 46 (including 0 and 46), with Mt_rand (0, 46).