I have written the following code in my HTML form:

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

The index only goes up in single digits to 10 obviously, is there a way that I can use two digits please? Example 01, 02, 03, 04......

I have tried pre-fixing a 0 or have i=01 but to no avail!

有帮助吗?

解决方案

Use sprintf(), which allows you to specify formatting/padding chars, like

$formatted = sprintf('%02d', $i); // 1 -> 01, 10 -> 10
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top