web-dev-qa-db-ja.com

整数phpをゼロフィル

整数を「ゼロフィル」するにはどうすればよいですか?

すなわち

1 becomes 0001
40 becomes 0040
174 becomes 0174
26
dotty
$filled_int = sprintf("%04d", $your_int)
71
Palantir
$number = 12;
$width = 4;
$padded = str_pad((string)$number, $width, "0", STR_PAD_LEFT); 
22
Joe