I have a couple array variables like so:
Code: Select all
$var = array ('FL' => 'florida', 'WY' => 'wyoming');
..and I want to be able to use a non-array variable to reference the proper key... example:
Code: Select all
$userState = 'FL';
echo $var[$userState]; // should output florida.
But I'm unsure how I actually "embed" that $userState variable within the array variable. Do I need to use double quotes? Single quotes? No quotes? etc.
ie...
Code: Select all
// Which one is right?
echo $var[$userState];
echo $var["$userState"];
echo $var['".$userState."'];
// etc etc.
Thank you for any help.