PHP – Select Menu with Current Month Selected

Here's a PHP class that displays the current month in a select menu list of months:

<?php
$curr_month = date("m");
$month = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "
<select name=\"month\">\n";
foreach ($month as $key => $val) {
    $select .= "\t<option val=\"".$key."\"";
    if ($key == $curr_month) {
        $select .= " selected=\"selected\">".$val."</option>\n";
    } else {
        $select .= ">".$val."</option>\n";
    }
}
$select .= "</select>
 
";
echo $select;
?>

I found this script on: http://www.finalwebsites.com/forums/topic/select-menu-with-current-month

Bookmark and Share

  1. PHP – Paginaton
  2. PHP – Validating an Email Addresss