简体   繁体   English

如何以4位数字打印?

[英]How can I print number in 4 digit?

I want to print a list of numbers in php. 我想在php中打印一个数字列表。
But I want to print 4 digits of numbers (preceding with zero if necessary), eg 但是我想打印4位数字(如果需要,可以打零),例如
0001, 0009, 0076, 0129, 1234 0001,0009,0076,0129,1234

What should I do? 我该怎么办?

printf("%04d", $num);
printf ('%04d' ,$num)

Look at the PHP Language Reference Manual and search for zero-padded integers 查看PHP语言参考手册并搜索零填充整数

The link gives the sprintf details, but the format string information applies to related functions like printf 该链接提供了sprintf详细信息,但格式字符串信息适用于printf等相关函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM