egturnkey Posted October 6, 2009 Share Posted October 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176633-i-wanna-make-it-multi-if-else-if-else-if/ Share on other sites More sharing options...
Philip Posted October 6, 2009 Share Posted October 6, 2009 I'd use a switch. switch($lang) { case 'ar': $language="arabic"; // run an include or whatever here... break; case 'es': $langauge = 'spanish'; break; case 'ru': $language = 'russian'; break; case 'en': default: $langauge = 'english'; break; } Quote Link to comment https://forums.phpfreaks.com/topic/176633-i-wanna-make-it-multi-if-else-if-else-if/#findComment-931204 Share on other sites More sharing options...
.josh Posted October 6, 2009 Share Posted October 6, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/176633-i-wanna-make-it-multi-if-else-if-else-if/#findComment-931216 Share on other sites More sharing options...
egturnkey Posted October 6, 2009 Author Share Posted October 6, 2009 thank you all for help your code KingPhilip , works perfect. problems solved and test working fine. Quote Link to comment https://forums.phpfreaks.com/topic/176633-i-wanna-make-it-multi-if-else-if-else-if/#findComment-931244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.