How to Create Unique Number in PHP?

Option-1:

$mt_rand = mt_rand(1000000000, 9999999999); 
echo $mt_rand;

Option-2:

$unique_id = uniqid();
echo $unique_id;
 uniqid( prefix, more_entropy ) 

prefix:
Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond.

With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.

more_entropy:
If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.

source: https://www.php.net/manual/en/function.uniqid.php

Option-3:

$mt_rand = mt_rand(1000000000, 9999999999);
$timestamp = time();
$temp = $mt_rand + $timestamp;
$temp2= substr($tmp, 0,10);

echo $temp2;

number_format() Function in Php

#Number Format Function in PHP

 

The number_format() function formats a number with grouped thousands.

 

Note: This function supports one, two, or four parameters (not three).

 

Syntax::

Syntax:

number_format(number,decimals,decimalpoint,separator)

 

Parameters::

ParameterDescription
numberRequired. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator.
decimalsOptional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point
decimalpointOptional. Specifies what string to use for decimal point
separatorOptional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, “xxx” will give the same output as “x”

Note: If this parameter is given, all other parameters are required as well

 

Example:

//Option-1
echo number_format("1000000")."<br>";

Output: 1,000,000


// Option-2
echo number_format("1000000",2)."<br>";

Output::1,000,000.00


//Option-3
echo number_format("1000000",2,",",".");

Output:: 1.000.000,00