<?php // RAY_Class_States.php
error_reporting(E_ALL);

Class States
{

    protected $states;
    protected $abbrs;

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

        $this->abbrs = array_keys($this->states);
    }

    // GET NAME FROM STATE ABBREVIATION
    public function getName($abbr)
    {
        $abbr = trim(strtoupper($abbr));
        if (!isset($this->states[$abbr])) return FALSE;
        return $this->states[$abbr];
    }

    // GET ALL NAMES FROM STATE ABBREVIATIONS
    public function getAllNames()
    {
        return $this->states;
    }

    // GET STATE ABBREVIATIONS
    public function getAllAbbrs()
    {
        return $this->abbrs;
    }

} // END CLASS States


// TEST CLASS STATES
if (!empty($_GET['s']))
{
   $s  = $_GET['s'];

   // INSTANTIATE THE CLASS
   $st = new States;

   // RETRIEVE AND ECHO THE DATA
   $nm = $st->getname($s);
   echo PHP_EOL . "$s NAME = $nm";

   // GET ALL THE ABBREVIATIONS
   $ab = $st->getallabbrs();
   $tx = implode(',', $ab);
   echo PHP_EOL . "ABBREVIATIONS FOR STATES: $tx";
}
?>
<form>
STATE ABBR:
<input name="s" />
<input type="submit" value="go" />
</form>