我必须按以下格式打印小于10的数值:
for 0 I want to print it 00
for 1 I want to print it 01
for 2 I want to print it 02
是否有以这种方式格式化数字的php库函数?
答案 0 :(得分:5)
答案 1 :(得分:2)
printf('%02u', $number)
答案 2 :(得分:2)
答案 3 :(得分:0)
您可以检查该值是否小于10并使用点运算符“。”连接,即
if($i < 10 && $i >0) print '0'.$i;
else print $i;