0
all right? I wonder how do I 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 is 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 of returning, for example:
<a href="ephelian">Ephélian</a>
<a href="lentzh">Lentzh</a>
<a href="gourphour">Gourphour</a>
He 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 believe I’m missing something that I’m not concatenating on this line:
$a_tag = implode('<a>', explode(',', ','.$valor['categorias_alt']));
Anyone who can shed a light, I thank ^_^
Why was my question negative? I was editing it. I ended up sending it unintentionally before finishing the editing
– Alex Lupóz