I'm trying to echo out the values of an array containing language information in a foreach-loop. Each language in het array contains a second array with a language description and a permalink of the current page. I want to use the permalink for creating hreflang tags in my site's header.
I have trouble accessing the correct values in the array. What is the best approach for this? I tried a foreach loop, but this returned a PHP notice 'array to string conversion' because I tried to echo out an array as a string.
My foreach loop looks like this:
$lang_list = stella_get_lang_list();
var_dump($lang_list);
foreach ($lang_list as $lang) {
foreach ($lang as $attr)) {
echo '<link rel="alternate" hreflang="' . $lang . '" href="' . $attr . '"/>';
}
}
This is the var_dump of the array:
array (size=4)
nl' =>
array (size=2)
'title' => string 'Dutch' (length=5)
'href' => string 'www.example.dev/page/' (length=24)
'en' =>
array (size=2)
'title' => string 'English' (length=7)
'href' => string 'www.example.dev/en/page/' (length=27)
'de' =>
array (size=2)
'title' => string 'German' (length=6)
'href' => string 'www.example.dev/de/page/' (length=27)
'fr' =>
array (size=2)
'title' => string 'French' (length=6)
'href' => string 'www.example.dev/fr/page/' (length=27)
Note: Stella is a Wordpress plugin, but I posted the question here because the essence of the problem is PHP related.