I’am doing a call to a database to retrieve an ID of a specific item. Usually there are the ids like: 1, 2, 14, 23, .... I need to get the ID from a DB and output it 4 digit number.
For exemple:
My result ID is: 1. Now i when i have this value, i want it to become 0001. Or if my result id is 13, it should became 0013, etc.
How can i achieve that with php without changing the real ID in database?
You want to zerofill an integer.
You could either do
sprintf('%04u', $n)orstr_pad($n, 4, '0', STR_PAD_LEFT).