Return to Snippet

Revision: 12761
at March 26, 2009 22:31 by rezzz


Initial Code
$us_states = array(
  array('id' => 1,'abbr' => 'AL', 'name' => 'Alabama'),
  array('id' => 2,'abbr' => 'AK', 'name' => 'Alaska'),
  array('id' => 3,'abbr' => 'AZ', 'name' => 'Arizona'),
  array('id' => 4,'abbr' => 'AR', 'name' => 'Arkansas'),             
  array('id' => 5,'abbr' => 'CA', 'name' => 'California'),
  array('id' => 6,'abbr' => 'CO', 'name' => 'Colorado'),
  array('id' => 7,'abbr' => 'CT', 'name' => 'Connecticut'),
  array('id' => 8,'abbr' => 'DE', 'name' => 'Delaware'),
  array('id' => 9,'abbr' => 'DC', 'name' => 'District of Columbia'),    
  array('id' => 10,'abbr' => 'FL', 'name' => 'Florida'),
  array('id' => 11,'abbr' => 'GA', 'name' => 'Georgia'),
  array('id' => 12,'abbr' => 'GU', 'name' => 'Guam'),
  array('id' => 13,'abbr' => 'HI', 'name' => 'Hawaii'),
  array('id' => 14,'abbr' => 'ID', 'name' => 'Idaho'),
  array('id' => 15,'abbr' => 'IL', 'name' => 'Illinois'),
  array('id' => 16,'abbr' => 'IN', 'name' => 'Indiana'),
  array('id' => 17,'abbr' => 'IA', 'name' => 'Iowa'),
  array('id' => 18,'abbr' => 'KS', 'name' => 'Kansas'),
  array('id' => 19,'abbr' => 'KY', 'name' => 'Kentucky'),
  array('id' => 20,'abbr' => 'LA', 'name' => 'Louisiana'),
  array('id' => 21,'abbr' => 'ME', 'name' => 'Maine'),
  array('id' => 22,'abbr' => 'MD', 'name' => 'Maryland'),
  array('id' => 23,'abbr' => 'MA', 'name' => 'Massachusetts'),
  array('id' => 24,'abbr' => 'MI', 'name' => 'Michigan'),
  array('id' => 25,'abbr' => 'MN', 'name' => 'Minnesota'),
  array('id' => 26,'abbr' => 'MS', 'name' => 'Mississippi'),
  array('id' => 27,'abbr' => 'MO', 'name' => 'Missouri'),
  array('id' => 28,'abbr' => 'MT', 'name' => 'Montana'),
  array('id' => 29,'abbr' => 'NE', 'name' => 'Nebraska'),
  array('id' => 30,'abbr' => 'NV', 'name' => 'Nevada'),
  array('id' => 31,'abbr' => 'NH', 'name' => 'New Hampshire'),
  array('id' => 32,'abbr' => 'NJ', 'name' => 'New Jersey'),
  array('id' => 33,'abbr' => 'NM', 'name' => 'New Mexico'),
  array('id' => 34,'abbr' => 'NY', 'name' => 'New York'),
  array('id' => 35,'abbr' => 'NC', 'name' => 'North Carolina'),
  array('id' => 36,'abbr' => 'ND', 'name' => 'North Dakota'),
  array('id' => 37,'abbr' => 'OH', 'name' => 'Ohio'),
  array('id' => 38,'abbr' => 'OK', 'name' => 'Oklahoma'),
  array('id' => 39,'abbr' => 'OR', 'name' => 'Oregon'),
  array('id' => 40,'abbr' => 'PA', 'name' => 'Pennsylvania'),
  array('id' => 41,'abbr' => 'PR', 'name' => 'Puerto Rico'),
  array('id' => 42,'abbr' => 'RI', 'name' => 'Rhode Island'),
  array('id' => 43,'abbr' => 'SC', 'name' => 'South Carolina'),
  array('id' => 44,'abbr' => 'SD', 'name' => 'South Dakota'),
  array('id' => 45,'abbr' => 'TN', 'name' => 'Tennessee'),
  array('id' => 46,'abbr' => 'TX', 'name' => 'Texas'),
  array('id' => 47,'abbr' => 'UT', 'name' => 'Utah'),
  array('id' => 48,'abbr' => 'VT', 'name' => 'Vermont'),
  array('id' => 49,'abbr' => 'VA', 'name' => 'Virginia'),
  array('id' => 50,'abbr' => 'VI', 'name' => 'Virgin Islands'),
  array('id' => 51,'abbr' => 'WA', 'name' => 'Washington'),
  array('id' => 52,'abbr' => 'WV', 'name' => 'West Virginia'),
  array('id' => 53,'abbr' => 'WI', 'name' => 'Wisconsin'),
  array('id' => 54,'abbr' => 'WY', 'name' => 'Wyoming')
);

function getStateNameByID($id)
{
	foreach ($us_states as $state) {
		if ($state["id"] == $id) {
			return $state["name"];
		}
	}
}

function getStateAbbrByID($id)
{
	foreach ($us_states as $state) {
		if ($state["id"] == $id) {
			return $state["abbr"];
		}
	}
}

function getStateIdByAbbr($abbr)
{
	foreach ($us_states as $state) {
		if ($state["abbr"] == $abbr) {
			return $state["id"];
		}
	}
}

function getStateIdByName($name)
{
	foreach ($us_states as $state) {
		if ($state["name"] == $name) {
			return $state["id"];
		}
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Multidimensional State Array

Initial Tags
php, textmate

Initial Language
PHP