php - Random 4 digit number excluding numbers 8 and 9 -
i need generate random 4 digit number, exclude 8 , 9 in generation.
here's code i'm using now, doesn't exclude 8 , 9,
rand(pow(10, 4 - 1), pow(10, 4) - 1);
this work well.
$allowednumbers = range(0, 7); $digits = array_rand($allowednumbers, 4); $number = ''; foreach($digits $d){ $number .= $allowednumbers[$d]; } echo $number; benefit here can specify allowed characters creating array of allowed digits. allow include character array including letters or words.
Comments
Post a Comment