Here are a few PHP functions that I find useful for United States related things. Nothing brilliant or groundbreaking – just something to save you some typing.

1. A PHP function for printing a state select box
2. A PHP function that returns the full state name when passed the abbreviation
3. A PHP snippet for printing a state select box

This function prints a state select box. It accepts the name of the box and the abbreviation of the state that you want selected.

   function printStateSelectBox($name, $selected){
      $state_arr=array( "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",
         "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA",
         "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE",
         "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC",
         "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY");

      $ret="";
      //print "selected is $selected";
      return ($ret);
   }

This function returns the state name when passed the abbreviation.

 function getStateNameByAbbreviation($state){
      if ($state=="AK"){ return "Alaska"; }
      if ($state=="AL"){ return "Alabama"; }
      if ($state=="AR"){ return "Arkansas"; }
      if ($state=="AZ"){ return "Arizona"; }
      if ($state=="CA"){ return "California"; }
      if ($state=="CO"){ return "Colorado"; }
      if ($state=="CT"){ return "Connecticut"; }
      if ($state=="DC"){ return "District of Columbia"; }
      if ($state=="DE"){ return "Delaware"; }
      if ($state=="FL"){ return "Florida"; }
      if ($state=="GA"){ return "Georgia"; }
      if ($state=="HI"){ return "Hawaii"; }
      if ($state=="IA"){ return "Iowa"; }
      if ($state=="ID"){ return "Idaho"; }
      if ($state=="IL"){ return "Illinois"; }
      if ($state=="IN"){ return "Indiana"; }
      if ($state=="KS"){ return "Kansas"; }
      if ($state=="KY"){ return "Kentucky"; }
      if ($state=="LA"){ return "Louisiana"; }
        if ($state=="MA"){ return "Massachusetts"; }
        if ($state=="MD"){ return "Maryland"; }
        if ($state=="ME"){ return "Maine"; }
        if ($state=="MI"){ return "Michigan"; }
        if ($state=="MN"){ return "Minnesota"; }
        if ($state=="MO"){ return "Missouri"; }
        if ($state=="MS"){ return "Mississippi"; }
        if ($state=="MT"){ return "Montana"; }
        if ($state=="NC"){ return "North Carolina"; }
        if ($state=="ND"){ return "North Dakota"; }
        if ($state=="NE"){ return "Nebraska"; }
        if ($state=="NH"){ return "New Hampshire"; }
        if ($state=="NJ"){ return "New Jersey"; }
        if ($state=="NM"){ return "New Mexico"; }
        if ($state=="NV"){ return "Nevada"; }
        if ($state=="NY"){ return "New York"; }
        if ($state=="OH"){ return "Ohio"; }
        if ($state=="OK"){ return "Oklahoma"; }
        if ($state=="OR"){ return "Oregon"; }
        if ($state=="PA"){ return "Pennsylvania"; }
        if ($state=="RI"){ return "Rhode Island"; }
        if ($state=="SC"){ return "South Carolina"; }
        if ($state=="SD"){ return "South Dakota"; }
        if ($state=="TN"){ return "Tennessee"; }
        if ($state=="TX"){ return "Texas"; }
        if ($state=="UT"){ return "Utah"; }
        if ($state=="VA"){ return "Virginia"; }
        if ($state=="VT"){ return "Vermont"; }
        if ($state=="WA"){ return "Washington"; }
        if ($state=="WI"){ return "Wisconsin"; }
        if ($state=="WV"){ return "West Virginia"; }
      if ($state=="WY"){ return "Wyoming"; }

   }

Another snippet for printing a State select box.

$state_list = array('AL'=>"Alabama",  'AK'=>"Alaska",  'AZ'=>"Arizona",  'AR'=>"Arkansas", 'CA'=>"California",  'CO'=>"Colorado",  'CT'=>"Connecticut",  'DE'=>"Delaware",'DC'=>"District Of Columbia",  'FL'=>"Florida",  'GA'=>"Georgia",  'HI'=>"Hawaii", 'ID'=>"Idaho",  'IL'=>"Illinois",  'IN'=>"Indiana",  'IA'=>"Iowa",  'KS'=>"Kansas", 'KY'=>"Kentucky",  'LA'=>"Louisiana",  'ME'=>"Maine",  'MD'=>"Maryland", 'MA'=>"Massachusetts",  'MI'=>"Michigan",  'MN'=>"Minnesota",  'MS'=>"Mississippi", 'MO'=>"Missouri",  'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio",  'OK'=>"Oklahoma",  'OR'=>"Oregon",'PA'=>"Pennsylvania",  'RI'=>"Rhode Island",  'SC'=>"South Carolina",  'SD'=>"South Dakota", 'TN'=>"Tennessee",  'TX'=>"Texas",  'UT'=>"Utah",  'VT'=>"Vermont",  'VA'=>"Virginia", 'WA'=>"Washington",  'WV'=>"West Virginia",  'WI'=>"Wisconsin",  'WY'=>"Wyoming");

foreach ($state_list as $k=>$v){
   if ($k == $select){
      $sv=" SELECTED ";
   }else{
      $sv="";
   }
   print " ";
}