I am trying to write a for loop in PHP to add to an HTML <select> tag dropdown, that allows people to pick their birth month.
Heres my code which isn’t working:
<p>
<label for="signup_birth_month">Birthday:</label>
<select name="signup_birth_month" id="signup_birth_month">
<option value="">Select Month</option>
<?php for ($i = 1; $i <= 12; $i++){
$month_name = date('F', mktime(0, 0, 0, $i, 1, 2011));
echo '<option value="'.$month_name.'"'.$month_name.'></option>';
}?>
</select>
</p>
How do I write a for loop that returns the name of each month in year?
You need to quote the
valuekey with:In addition, I’d probably prefer something like this:
It seems bizarre that you would make all those unnecessary calls to
dateandmktimewhen you know what the values should be.This array version has the same number of lines and it seems a lot clearer in intent (at least to me).