Initial file:
require_once '../../translator.php';
translateTo('es');
//Resto del código
translator.php file:
function translateTo($language){
if ($language == 'es'){
require_once 'lang_es.php';
}else{
require_once 'lang_en.php';
$language = 'en';
}
}
And for example, in the lang_es.php file (which is at the same level as translator.php):
$lang = array(
'key' => 'palabra en español'
);
When I try to 'echo $lang['key']' on the initial file, it returns nothing.
When making the inclusion inside a function, the scope of the included file is restricted to that function.
You have more information in the official documentation: http://php.net/manual/es/language.variables.scope.php )
Could you do:
In translator.php
and in initial file