PHP Generate 4 Digit Unique Random Numbers Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Today now in this blog, i will tell you how we can generate 4 digit unique random numbers by using php. Here we will see how touse random function by using in php to generate 4 digit random numbers. So here we can easily create 4 digit unique random in php.

Now we are show generate 4 digit unique random numbers also with example. So now from here we can create the random number of Four digits by using PHP.

Now i will show you two different functions to generate 4 digit random numbers. At first we will generate 4 unique random numbers for function mt_rand() and then second one generate 4 unique random numbers by using function rand().

Now here the following example for generate 4 digit unique random numbers.

Example 1

Now here the example mt_rand() function using generate 4 digit unique random numbers

<?php
    $fourRandomDigit = mt_rand(1000,9999);
    echo $fourRandomDigit;    
?>
Example 2

So here the example rand() function using generate 4 digit unique random numbers

<?php
    $fourRandomDigit = rand(1000,9999);
    echo $fourRandomDigit;
?>

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →