<?php
$lang = [
'en' => [
'name' => 'English',
'dir' => 'ltr',
],
'es' => [
'name' => 'Spanish',
'dir' => 'ltr',
],
'fr' => [
'name' => 'French',
'dir' => 'ltr',
],
];
$lang2 = array_map(
function ($key) use ($lang) {
return [$key => $lang[$key]];
},
array_keys($lang)
);
print_r($lang2);
outputs ...
Array
(
[0] => Array
(
[en] => Array
(
[name] => English
[dir] => ltr
)
)
[1] => Array
(
[es] => Array
(
[name] => Spanish
[dir] => ltr
)
)
[2] => Array
(
[fr] => Array
(
[name] => French
[dir] => ltr
)
)
)
Hope that helps.
@RQuadling - Thanks for helping, but that actually wasn't what I wanted. In my original filters.php I have
App::before(function($request)
{
$url = explode('.', $request->server('HTTP_HOST'));
$langcode = $url[1];
$languages = ['en','fr'];
if ( in_array($langcode, $languages) ){
echo "yes";
App::setLocale($langcode);
}else{
echo "no";
}
});
And this code allows me to be able to select what languages i'm using via the $languages array. So what I'm trying to do is create a php file that has a list of languages that I will be using, so instead of doing something like this
$languages = ['en','fr', 'es', 'ch', 'af', 'de', 'hr', 'ar', 'ru', 'mn', 'el', 'he', 'ja', 'pol',];
where if I have alot of languages to use it will start to look untidy. So all I would have to do is call it like this
$languages = Config::get('languages.supportedLang');
now the problem comes in around this line
if ( in_array($langcode, $languages) )
this line checks what the $langcode is and then it will have a look at $languages to see if it is in that array and if it is then it would do what it's suppose to do.
But $languages needs to be an array. Where the languages would look like this if I print_r $languages
Array
(
[0] => en => Array
(
[name] => English
[dir] => ltr
)
[1] => es => Array
(
[name] => Spanish
[dir] => ltr
)
[2] => fr => Array
(
[name] => French
[dir] => ltr
)
)
Is this explanation better? I'm not sure how to word what I need.
Try replacing ...
if ( in_array($langcode, $languages) )
with ...
if ( in_array($langcode, array_keys($languages) ) )
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community