PHP中的日历下拉:保持选定的值并重新使用该功能

I have found online the following PHP function on defining a calendar drop-down (in month/day/year format). The function is working fine, but I would like:

a) Keep the selected value for Month, Day and Year, so to be able to edit values easily (values are defined dynamically through a foreach loop), and

b) would like to re-use the function on multiple variables (so far, I am using it to define date of birth, but I would like to use the same function also on additional fields too).

The fact that the values for Month, Day and Year are defined dynamically is a little bit confusing me, and of course I am not fluent in functions definition yet. Any help would be greatly appreciated !

Here is the function:

function make_calendar_pulldowns() {

    // Make the months array:
    $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

    // Make the months pull-down menu:
    //echo '<p><label for="dob" style="font-family: Verdana, Arial; font-size: 1.0em; font-weight: 600; color: #595959; line-height: 1.9em;">Date of Birth</label></p>';
    echo '<select required="required" name="month" id="month" style="width: 33%; display: inline; float: left; margin-left: 1%; margin-right: 0%">';
    echo '<option selected value="">Month</option>
';
    foreach ($months as $key => $value) {
        echo "<option value=\"$key\" >$value</option>
";
    }
    echo '</select>';

    // Make the days pull-down menu:
    echo '<select required="required" name="day" id="day" style="width: 33%; display: inline; float: left; margin-left: 0%; margin-right: 0%" ;>';
    echo '<option selected value="">Day</option>
';
    for ($day = 1; $day <= 31; $day++) {
        echo "<option value=\"$day\">$day</option>
";
    }
    echo '</select>';

    // Make the years pull-down menu:
    echo '<select required="required" name="year" id="year" style="width: 33%; display: inline; float: left; margin-left: 0%; margin-right: 0%" ;>';
    echo '<option selected value="">Year</option>
';
    for ($year = 1910; $year <= 2000; $year++) {
        echo "<option value=\"$year\">$year</option>
";
    }
    echo '</select>';

Once values have been defined, I convert them to MySQL format with the following code:

// Validate the month.
if (is_numeric ($month)) {
    $dob = $month . '-';

} else {
    $action['result'] = 'error'; 
    array_push($text,'Please insert a valid Month for patient birth date');
}
// Validate the day.
if (is_numeric ($day)) {
    $dob .= $day . '-';

} else {
    $action['result'] = 'error'; 
    array_push($text,'Please insert a valid Day for patient birth date');
}
// Validate the year.
if (is_numeric ($year)) {
    $dob = $year . '-' . $month . '-' .  $day; // Set Birthdate in SQL format

Finally, I call the function in the form with the following code:

<!-- <p><label for="dob">Date of Birth <img src="../img/req.gif" alt="Required"</label></p>
<?php make_calendar_pulldowns(); ?> -->

Actually some parts of it are a bit off:

// Make the months array:
$months = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
// some months are a bit off, the keys are missing
// Should be something like this:

$months = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$month_num = range(1, 12);
$months = array_combine($month_num, $months);

And the days are hardcoded, what about February 31?

The Years I guess should be okay.

Why not use a date picker (jQuery UI in particular) for this purpose instead?

$(function() {
    $( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd', // iso format
    });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

<form method="POST">
  <p>Date: <input type="text" id="datepicker" name="date"></p>
  <input type="submit" name="submit1" />
</form>

Then in PHP, just call it like a normal $_POST

if(isset($_POST['submit1'])) {
    $date = $_POST['date'];
}

More API Info: http://jqueryui.com/datepicker/

</div>