i'm trying echo out values of array containing language information in foreach-loop. each language in het array contains second array language description , permalink of current page. want use permalink creating hreflang tags in site's header.
i have trouble accessing correct values in array. best approach this? tried foreach loop, returned php notice 'array string conversion' because tried echo out array string.
my foreach loop looks this:
$lang_list = stella_get_lang_list(); var_dump($lang_list); foreach ($lang_list $lang) { foreach ($lang $attr)) { echo '<link rel="alternate" hreflang="' . $lang . '" href="' . $attr . '"/>'; } } this var_dump of 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 wordpress plugin, posted question here because essence of problem php related.
foreach ($lang_list $langid => $lang) { echo '<link rel="alternate" hreflang="' . $langid . '" href="' . $lang['href'] . '"/>'; }
Comments
Post a Comment