here is my code
i want it to if the statment does not exists return the key value
like 'something' in last line of code but it's not working
function getTranslation($translations, $lang, $statement)
{
$lang = $translations[$lang];
$statement = $lang[$statement];
return $statment;
}
$translations = [
'fa' => ['Hello!' => 'hi!', 'Hi!' => 'hi!'],
'fr' => ['Hello!' => 'Bonjour!']
];
echo getTranslation($translations, 'fa', 'Hi!');
echo PHP_EOL;
echo getTranslation($translations, 'fr', 'Hello!');
echo PHP_EOL;
echo getTranslation($translations, 'fr', 'Something');
My Answer:
> 'سلام',
> 'en' => 'hello',
> 'fr' => 'bonjour'
];
echo getTranslation($translations, 'en', 'hello'); // Output: hello
echo getTranslation($translations, 'fa', 'something'); // Output: something
Rate this post
3 of 5 based on 7166 votesComments