Jump to content

i wanna make it multi ( if else if else if ..)


egturnkey

Recommended Posts

Hello Dear Friends,

 

say we have 2 lang (en,ar) which can be set by following code

 

if($lang == "en") {
include_once "lang/english/co_en.php";
}  else if($lang == "ar") {
include_once "lang/arabic/co_ar.php";
}

 

and

 

if($lang == "en")
   $language="english";
else if($lang == "ar")
   $language="arabic";

 

 

what if we added es,ru so we have 4 (en,ar,es,ru)

 

how then can we rewrite the above code in case of 4 ??

 

thanks in advance

if all of the files follow that same format, just do something like this:

 

$lang = 'ar';
$languages = array('en','ar','ru','es'); // add languages here
$file = (in_array($lang,$languages))? 'co_'.$lang.'.php' : 'co_'.$languages[0].'.php'; // change array elem to whatever you want as default
include_once $file;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.