Adrian World Design
  • Services
    • Website Consulting
    • Startup Consulting
    • Zend Development
  • Portfolio
    • My Framework
  • Knowledge
    • Web Standards
    • PHP bare-bones
    • Zend Framework
    • Zend Framework 2
    • Git - Github
    • Search Engine Optimization
    • Web Hosting
    • Linux
    • Microsoft Windows
    • Web Browsers
    • Mobile Devices
  • About
    • Business
    • Professionally
    • Personally
  • Contact
    • Contact Form
    • Phone
    • Email
    • Messaging

Knowledge Base Overview

Array List with U.S. States

Knowledge ⇒ Zend Framework ⇒ Helpful Tips ⇒ Array List with U.S. States
Tweet
Share on Tumblr

Created: Oct 9, 2011, 3:45:18 PM CDTLast updated: Dec 31, 2011, 11:22:25 AM CDT

US states list

So, you need a php array list with all the US states? Right on, I have the list ready for you in a php array and even as a static method you can add to a class object. 

If you click the following link you will get a simple txt document with the US states list. This makes it real easy for you to copy/past the list into your PHP project. You can see how the array in the link will look like below.

  • US-States.txt

If you like to read why I have this copy/paste list then see below. Actually it is more about search engines. Without it they would not index this page. That's how SEO works, I guess.

PHP Array

I have this page and list because I had a problem and maybe you have a similar problem.

You work with the Zend Framework (or another CMS like Wordpress, Joomla or just a plain PHP project). You project requires a form with a select element where users can select the US state they live in. Therefore, you need this: a PHP array with the United States (US).

If you work with the Zend Framework you might think there is a solution with Zend_Locale, just like the one for the country list. Unfortunately there is none and revert to Google to find either a list or some array ready for copy/pase.

Hence, I was looking for an array (not just a list) ready with all these United States in America (USA). What I found was web pages with all sorts of lists but a page where you can easily copy/paste a ready to go PHP array with all states? Not one that exactly had what I was looking for. Most of them were not properly formatted or even worse behind lots and lots of annoying ads and other garbage.

So I create this page with the US-States.txt document. I contains all the United States of America in an array, in case you need one as simple as that.

I have even included the whole array as a static function. You can paste the function into a class as a method. It sports an argument for retrieving just one single state with the abbreviation.

If you are looking for the array on this page here it is below. Although, I highly recommend the txt document above—it is way better for copy/paste.

// a simple PHP array for copy/paste
$usStates = array(
  'AL' => 'Alabama',
  'AK' => 'Alaska',
  'AZ' => 'Arizona',
  'AR' => 'Arkansas',
  'CA' => 'California',
  'CO' => 'Colorado',
  'CT' => 'Connecticut',
  'DE' => 'Delaware',
  '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',
);
blog comments powered by Disqus
Prev
Next

Powered by FeedBurner Load our "Knowledge Base" feed in your RSS feeder

Follow us on Twitter
Follow us on Facebook
Follow us on LinkedIn
Follow us on Google+

All rights reserved, Adrian World Design ©2009–2022 Powered by Wejas Framework

Jump to Top