I need a suggestion on a function for a php counter. Is there any function to have numbers with 5 digit as 00001, or 00123… this number should be not random but have to increase the value of a previous field.
If a number is $n=’00001’ there is a function to increase by one and get 00002 and not 2?
Thanks F.
$number = 1;
$number++;
echo str_pad($number, 5, "0", STR_PAD_LEFT); //00002
$n2 = str_pad($n + 1, 5, 0, STR_PAD_LEFT);
Use str_pad()
by adding 0
s (third parameter) to the left (fourth parameter) of the old number $n
incremented by 1
(first parameter) until the length is 5 (second parameter).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With