<?php
array("seccao" => "sec1", "imagem" => "img1"), array("seccao" => "sec1", "imagem" => "img2"), array("seccao" => "sec1", "imagem" => "img3"), array("seccao" => "sec2", "imagem" => "img1"), array("seccao" => "sec3", "imagem" => "img1"), array("seccao" => "sec3", "imagem" => "img2"), array("seccao" => "sec3", "imagem" => "img3"), array("seccao" => "sec4", "imagem" => "img1") );
$atualUl = "";
for ($i = 0; $i < count($resultado); $i++) { $registo = $resultado[$i];
// precisa criar nova tag
if ($registo["seccao"] != $atualUl) {
// precisa fechar a tag anterior
if ($atualUl != "") {
echo '</ul>';
}
// criando a tag
echo '<ul>';
// atualiza o atual
$atualUl = $registo["seccao"];
}
echo "<li>" .$registo["seccao"]. "/" . $registo["imagem"] . "</li>";
}
// fecha ultima tag
echo '</ul>';
PD9waHAKCQoJCgkkcmVzdWx0YWRvID0gYXJyYXkoCgkJYXJyYXkoInNlY2NhbyIgPT4gInNlYzEiLCAiaW1hZ2VtIiA9PiAiaW1nMSIpLAoJCWFycmF5KCJzZWNjYW8iID0+ICJzZWMxIiwgImltYWdlbSIgPT4gImltZzIiKSwKCQlhcnJheSgic2VjY2FvIiA9PiAic2VjMSIsICJpbWFnZW0iID0+ICJpbWczIiksCgkJYXJyYXkoInNlY2NhbyIgPT4gInNlYzIiLCAiaW1hZ2VtIiA9PiAiaW1nMSIpLAoJCWFycmF5KCJzZWNjYW8iID0+ICJzZWMzIiwgImltYWdlbSIgPT4gImltZzEiKSwKCQlhcnJheSgic2VjY2FvIiA9PiAic2VjMyIsICJpbWFnZW0iID0+ICJpbWcyIiksCgkJYXJyYXkoInNlY2NhbyIgPT4gInNlYzMiLCAiaW1hZ2VtIiA9PiAiaW1nMyIpLAoJCWFycmF5KCJzZWNjYW8iID0+ICJzZWM0IiwgImltYWdlbSIgPT4gImltZzEiKQogICAgKTsKCQoJJGF0dWFsVWwgPSAiIjsKICAgIGZvciAoJGkgPSAwOyAkaSA8IGNvdW50KCRyZXN1bHRhZG8pOyAkaSsrKSB7Ci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