I try to create a Helper function which shall replace the short names of language to their full names.
I have a constants file which looks like this (using laravel that is why the constant looks like this):
<?php
return [
'languages' => [
'names' => [
'Bulgarian' => 'bg',
'Danish' => 'da',
'German' => 'de',
'English' => 'en'
...
],
]
];
My function so far looks like this:
public static function replaceName($string = '')
{
$langName = Config::get('constants.languages.names');
foreach($langName as $langKey => $langValue)
{
$search = array($langValue);
$replace = array($langKey);
}
return str_replace($search, $replace, $string);
}
But it still does not work any ideas?
return str_replace(array_keys( $langName), $langName, $string);elsereturn str_replace($langName,array_keys( $langName), $string);depart in it?