I want to be able to call a function, that will set one or more local variables in the calling function. For instance:
function someFunc () {
loadTranslatedStrings($LOCALS, "spanish");
echo $hello; // prints "hola";
}
function loadTranslatedStrings (&$callerLocals, $lang) {
if ($lang == 'spanish')
$callerLocals['hello'] = 'hola';
else if ($lang == 'french')
$callerLocals['hello'] = 'bonjour';
else
$callerLocals['hello'] = 'hello';
}
(I'm guessing it is impossible to do this, but might as well ask...)
You could do this...
function someFunc () {
loadTranslatedStrings($lang, "spanish");
extract($lang);
echo $hello; // prints "hola";
}
CodePad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With