1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Variable variablename used for array?

Discussion in 'PHP' started by PoPSiCLe, May 18, 2009.

  1. #1
    Hi.

    I have a little problem, and I was hoping someone can point me in the right direction, cause I seem to have hit a dead end.

    As an example, we put forth the following code:

    
    if ($_SESSION['language'] == "english") {
    	$lang = "_en";
    } elseif ($_SESSION['language'] == "norwegian") {
    	$lang = "_no";
    	} else {
    		$lang = '_no';
    		}
    
    $array_en = ("january","february","march","april","may","june");
    $array_no = ("januar","februar","mars","april","mai","juni");
    //months in arrays, namely in english and norwegian
    //then we define:
    	define ("__MONTHS_ALPHA",serialize($array_SOMETHING));
    
    PHP:
    What I would like is a way to use the $lang-variable to add to the $array-variable used in the serialize-statement. Eg. if the $lang-variable is "_no" I would like the $array-variable to turn into $array_no and get the values used in the $array_no-variable which is shown above.

    Anyone? My brain is hurting right now :)
     
    PoPSiCLe, May 18, 2009 IP
  2. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #2
    
    $array_months['_en'] = ("january","february","march","april","may","june");
    $array_months['_no'] = ("januar","februar","mars","april","mai","juni");
    //months in arrays, namely in english and norwegian
    //then we define:
        define ("__MONTHS_ALPHA",serialize($array_months[$lang]));
    
    PHP:
    That should work i think...
     
    killaklown, May 18, 2009 IP
    PoPSiCLe likes this.
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Jeez. Thank you, thank you, thank you! :D

    *hits self over the head for not thinking a BIT simpler*
     
    PoPSiCLe, May 18, 2009 IP