I have a function that generates a random number, like:
$int = random_number();
Generally, the results are 6 digits, but occasionally, it ends up being less than 6 digits. How do I add zeros to the number if it is less than 6 digits? For example, if $int
is 12345
, I turn it into 123450
.
I can easily do this with something like:
if (strlen($int) == 5) {
$int = $int.'0';
} elseif(strlen($int) == 4){
$int = $int.'00';
} //etc
But clearly there must be a better way?