Below is an old PHP function I have for a dropdown list for users to select there birthdate, this is just the day date portion of it, you can see that it uses str_pad to add on a 0 to the numbers 1-9, is there a better way of doing this?
<?PHP
$date_combo .= '<select name="' . $pre . 'day" class="' .$style. '">';
$date_combo .= "<option value=''>Day</option>";
for ($i = 1; $i <= 31; $i++) {
$date_combo .= " <option ";
if ($i == $selected_date_day) {
$date_combo .= " selected ";
}
$date_combo .= " value='" . str_pad($i, 2, "0", STR_PAD_LEFT) . "'>" . str_pad($i, 2, "0", STR_PAD_LEFT) . "</option>";
}
$date_combo .= "</select> ";
echo $date_combo;
?>