Alright? I would like to know how to add the respective value in "href" in this foreach:
<?php
$getJson = file_get_contents('file.json');
$listMenuJson = json_decode($getJson, true);
foreach ($listMenuJson as $valor) {
$a_tag = implode('<a>', explode(',', ','.$valor['categorias_alt']));
echo '<div class="btn-group">';
echo '<div class="dropdown">';
echo '<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">'.$valor['titulo'];
echo '<span class="caret"></span></button>';
echo '<ul class="dropdown-menu">';
echo '<li>';
echo '<a href="'.$valor['codigo'].'">'.$valor['categorias'].'</a>';
echo '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
?>
My JSON looks like this:
[
{
"codigo":"termos",
"titulo":"Termos Gerais",
"categorias_alt":"Ephélian, Lentzh, Gourphour",
"categorias":"ephelian, lentzh, gourphour"
},
{
"codigo":"contos",
"titulo":"Contos & Lendas",
"categorias_alt":"Ephélian, Lentzh, Gourphour",
"categorias":"ephelian, lentzh, gourphour"
},
{
"codigo":"cabinet",
"titulo":"Cabinet Escarlate",
"categorias_alt":"Ephélian, Lentzh, Gourphour",
"categorias":"ephelian, lentzh, gourphour"
}
]
In case, this part here:
echo '<a href="'.$valor['codigo'].'">'.$valor['categorias'].'</a>';
The system works, but instead returns, for example:
<a href="ephelian">Ephélian</a>
<a href="lentzh">Lentzh</a>
<a href="gourphour">Gourphour</a>
It returns this:
<a href="ephelian,lentzh,gourphour">Ephélian</a>
<a href="ephelian,lentzh,gourphour">Lentzh</a>
<a href="ephelian,lentzh,gourphour">Gourphour</a>
I think I'm letting something go that I'm not concatenating in this line:
$a_tag = implode('<a>', explode(',', ','.$valor['categorias_alt']));
Who can give a light, I thank ^ _ ^