문제

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