I'm trying to generate invoice numbers. They should always be 4 numbers long, with leading zeros, for example :
etc.
You can use sprintf("%02d", $number) to format strings.
Use sprintf() Function to Show a Number to Two Decimal Places in PHP. Copy sprintf($format, $parameter1, $parameter2, ... , $parameterN); The parameter $format is the format that specifies how the variables will be in the string.
Use str_pad().
$invID = str_pad($invID, 4, '0', STR_PAD_LEFT);
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