0

I'd like to make a language switcher, but the default options don't work for me, so I'd like to use the 'raw' attribute. I'm currently just testing whether my languages will show up at all:

$translations = pll_the_languages(array('raw'=>1));
echo $translations[0]['name'];

This code doesn't output anything, but doesn't crash the website either. What am I missing?

TeunCB
  • 33
  • 5

2 Answers2

0
$translations = pll_the_languages(array('raw'=>1));
echo $translations[nl][name];

I thought the second array would be named after the 'order' number of the language, turns out it was the slug. Thanks to Danyal for helping me find the array's framework.

TeunCB
  • 33
  • 5
0

you would need to get it like this:

echo $translations['nl']['name'];

It's better to verify if the key exists in the array or not.

$value= "";
if($key_exists('nl',$translations) && $key_exists('name',$translations['nl'])){
$value = $translations['nl']['name'];
}
echo $value;
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78