How to simplify this php switch statement?

Posted by janoChen on Stack Overflow See other posts from Stack Overflow or by janoChen
Published on 2010-03-16T16:02:33Z Indexed on 2010/03/16 16:11 UTC
Read the original article Hit count: 455

Filed under:
|

I would like to change this:

// use appropiate lang.xx.php file according to the value of the $lang
switch ($_SESSION['lang']) {
case 'en':
    $lang_file = 'lang.en.php';
    break;

case 'es':
    $lang_file = 'lang.es.php';
    break;

case 'zh-tw':
    $lang_file = 'lang.zh-tw.php';
    break;

case 'zh-cn':
    $lang_file = 'lang.zh-cn.php';
    break;

default:
    $lang_file = 'lang.en.php';
}

into something like this:

//include file for final output
    include_once 'languages/lang.'.$_SESSION['lang'].'php;

So that I can skip the whole switch part. I tried other combinations but they don't seem to work. Any suggestions?

© Stack Overflow or respective owner

Related posts about php

Related posts about switch