使用两位数进行索引

时间:2013-08-16 17:18:56

标签: indexing double digits

我在HTML表单中编写了以下代码:

<select name="createdDay"><?php for ($i=1; $i <= 31 ; $i++) 
{echo '<option>' . $i . '</option>';} ?>

索引显然只有单位数增加到10,请问有两种数字可以使用吗?例01,02,03,04 ......

我尝试过预先修复0或者i = 01但是无济于事!

1 个答案:

答案 0 :(得分:1)

使用sprintf(),它允许您指定格式/填充字符,例如

$formatted = sprintf('%02d', $i); // 1 -> 01, 10 -> 10