zerofill a integer php
Question
How would I go about 'zero filling' an integer?
ie
1 becomes 0001
40 becomes 0040
174 becomes 0174
Solution
$filled_int = sprintf("%04d", $your_int)
OTHER TIPS
$number = 12;
$width = 4;
$padded = str_pad((string)$number, $width, "0", STR_PAD_LEFT);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow