Translate

In this coding Tutorial, We are generating random number with four digit uniquely. We can use this random number generation into many ways in PHP Programming. We can use this random number after or before any image or file for storing information into database for future use.

We can simply write this code with Example: -


$uniquenumber_long      = uniqid(rand(), true);
$fourdigit_uniquenumber = substr(str_shuffle($uniquenumber_long), 0, 4);
$final_random_code      = preg_replace('/[^a-zA-Z0-9_ -]/s', '', $fourdigit_uniquenumber); 


In this code, first we are using rand function of PHP and after that providing this function a number value for number generation start number to end number. Then converting this into final_random_code variable. When we refresh this code again then we will get new random code each time.

You Might Also Read: - 

0 comments:

Post a Comment

 
Top