tags:

views:

92

answers:

4

I want to print a list of numbers in php.
But I want to print 4 digits of numbers (preceding with zero if necessary), e.g.
0001, 0009, 0076, 0129, 1234

What should I do?

+1  A: 

printf

David Dorward
+12  A: 
printf("%04d", $num);
Ignacio Vazquez-Abrams
+2  A: 
printf ('%04d' ,$num)
ghostdog74
A: 

Look at the PHP Language Reference Manual and search for zero-padded integers

The link gives the sprintf details, but the format string information applies to related functions like printf

pavium