我想根据类别名称为joomla k2中的项目列表创建一个过滤器。 我能够从所有项目中获取类别名称,但是有相同类别的项目,因此我获得了重复的类别名称。 这是我的代码
<div class="btn-toolbar filters">
<?php
$numofitems = count($items);
if($numofitems)
{
foreach ($items as $key=>$item)
{
?>
<div data-toggle="buttons" class="btn-group">
<label class="btn btn-default">
<input type="checkbox" value="<?php echo $item->categoryalias; ?>" >
<?php echo $item->categoryname; ?>
</label>
</div>
<?php } ?>
<div class="clr"></div>
<?php } ?>
</div>
我想我需要一个数组,然后从这个数组中获取唯一值,但我真的很厌烦用PHP。 这里演示链接Demo
答案 0 :(得分:0)
你总是可以尝试使用PHP的array_unique函数,它可以简单地从数组中删除重复项。
因此请使用以下内容替换当前的foreach
循环。
foreach (array_unique($items) as $key=>$item) {
// rest of code here
}