How do I start a for-loop with 01
as opposed to 1
? I've tried the below, but it doesn't seem to work.
for ($i = 01; $i <= 12; $i++) {
echo "<option value='$i'";
if ($i == $post_response[expiremm]) {
echo " selected='selected'";
}
$month_text = date("F", mktime(0, 0, 0, $i+1, 0, 0, 0));
echo ">$month_text</option>";
}
You can't really start an integer at 01, you will need to pad the value, probably using
str_pad
to prefix leading elements to a string:Note that for different unit types you will obviously need to alter the desired
pad_length
.it may help you..
PHP will parse 01 as an integer, so it will become 1. You can't iterate on a string like '01' so you'll have to edit the value of $i later on in your code.
If you need a 01 later on, you could use padding. http://php.net/manual/en/function.str-pad.php
01
is the octal number1
(which is equivalent to the decimal1
in this case). Since you want to format the output to have two digits for the number, consider usingprintf
:%
marks the start of a conversion0
means "pad the string with zero"2
means "the replacement should have a minimum length of 2"d
means "the argument is an integer"References:
For loop can not start with 01 so you can do like this as shown above