public static function generateReceiptNumber(int $id) { $receipt_number = sprintf(' d', $id % 100000000); return $receipt_number; }
I am using the above code to convert the incoming $id to a minimum 6 digit, maximum 8 digit number. For example: 000001 - 99999999
But there is a flaw in this code. When $id equals 100000000, it will return 000000. How should I improve the above code to return 000001?
By analogy, $id is the auto-incremented ID of the database.
The reason I want to achieve this is because I have a display text box with a text limit of only 8 digits and I can only count the numbers back up from 000001 and keep repeating.
Please see if this answer helps
How about this: