Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make 4 digit integer from one, two, or three digits integer in PHP

Tags:

php

integer

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?

like image 702
aspirinemaga Avatar asked Aug 13 '12 10:08

aspirinemaga


1 Answers

Same as always.

sprintf("%04d", $num)
like image 69
Ignacio Vazquez-Abrams Avatar answered Oct 28 '22 19:10

Ignacio Vazquez-Abrams