Create New Form Value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Becca800
Forum Newbie
Posts: 5
Joined: Wed Oct 24, 2007 10:25 pm

Create New Form Value

Post by Becca800 »

Hey there, php is not my strong point. I can't write my own php to save my life, but if I have a snippet I can usually figure out how to tweak it.

I have a form which autopopulates a few form fields when the user enters his/her zip code, the city and state fields are populated from a mysql db. The state field is an abbreviated version of the state. I need to create a new value from the state value using php. So if the state is AL, I need to be able to have a new value "Alabama", if the state is CA, I need a new value for "california", etc. Does anyone know how I can do this? I need both values, so it isn't that I would need to rename the value. Thanks.
ramya123
Forum Newbie
Posts: 13
Joined: Thu Sep 11, 2008 6:11 am

Re: Create New Form Value

Post by ramya123 »

You can use Associative array in order to achieve this

Code: Select all

 
$state = array("AL"=>"Alabama","CA"=>"california");
 
Here we can use the values as keys and assign values to them.The ID keys can be used in a script:

Code: Select all

 
$state['AL'] = "Alabama";
$state['CA'] = "california";
 
Post Reply