zerofill a integer php

dotty picture dotty · Sep 18, 2009 · Viewed 34.6k times · Source

How would I go about 'zero filling' an integer?

ie

1 becomes 0001
40 becomes 0040
174 becomes 0174

Answer

Palantir picture Palantir · Sep 18, 2009
$filled_int = sprintf("%04d", $your_int)