From an Array to a Variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    From an Array to a Variable

    Code:
    $lang = array(
    'red'       => 'red',
    'green'     => 'green',
    'brown'         => 'brown'
    );
    I've tried these:
    Code:
    $thiscolor = "{$lang['green']}";
    $thiscolor = {$lang['green']};
    $thiscolor = $lang['green'];
    But the variable will not pick up the color. What's wrong?
    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Third option works fine for me. You will need to explain what you mean by "will not pick up the color". Because when I output $thiscolor using line 3, I get the expected output string of 'green'.

    Comment

    • DavidPr
      New Member
      • Mar 2007
      • 155

      #3
      Hmmm, you're right...it is working. I must have inadvertently put an apostrophe or something in the actual code and missed it. Sorry for the trouble, but thanks for your help.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        No worries, everyone makes mistakes.

        Comment

        Working...