Pregunta

¿Cómo haría para 'rellenar cero' un número entero?

es decir

1 becomes 0001
40 becomes 0040
174 becomes 0174
¿Fue útil?

Solución

$filled_int = sprintf("%04d", $your_int)

Otros consejos

$number = 12;
$width = 4;
$padded = str_pad((string)$number, $width, "0", STR_PAD_LEFT); 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top