PHP Function for a List of States for HTML Forms

The following PHP function produces this textbox: 

It is useful for keeping your main code clean and legible—just stick this function in an external file and call it whenever necessary. It records the states as two-letter abbreviations and displays them in full. It can be easily edited to include any additional territories or converted to use for countries.

Be sure to also check out other pages in this section of my site if you are creating a database-driven site—I provide a MySQL state table somewhere in there.

// List the states in a select box to keep the main code clean.
function displayStateBox() {
     $states = array(

         array("AL", "Alabama"),
         array("AK", "Alaska"),
         array("DC","Dist of Columbia"),
         array("NH","New Hampshire"),
         array("NJ","New Jersey"),
         array("NM","New Mexico"),
         array("NY","New York"),
         array("NC","North Carolina"),
         array("ND","North Dakota"),
         array("RI","Rhode Island"),
         array("SC","South Carolina"),
         array("SD","South Dakota"),
         array("WV","West Virginia"),

     // Open the select box.
     print '<select name="state">' . "\n";

     // Uncomment the below line to make the first option "--SELECT--".
     // print '<option value="XX">--SELECT--</option>\n";

     // Cycle through the array, printing each option.
     foreach ($states as $s) {
         print '<option value="' . $s[0] . '"*gt;' . $s[1] . "</option>\n";

     // Close the select box.
print "</select>\n";
} // End function displayStateBox()