【发布时间】:2015-02-10 12:21:36
【问题描述】:
您好,我正在尝试使用 wordpress 遍历标签列表。标签列表是通过另一个插件生成的。
目前这是我的代码
<?php foreach($entities as $entity): ?>
<?php $str = str_replace(' ', '-', esc_attr($entity->galdesc)) ?>
<li><a href="#" id="<?php echo $str ?>"><?php echo_safe_html(nl2br($entity->galdesc)); ?></a></li>
<?php endforeach ?>
这样输出标签列表如下
tag1
tag1
tag2
tag1
tag3
所有标签都会这样,但我正在尝试删除重复项,我已经研究过使用 array_unique 但无法使其正常工作。
谢谢
【问题讨论】:
-
您是否尝试使用 $entity->galdesc 格式化新数组,然后对其调用 array_unique ?
-
我不知道该怎么做?我尝试了各种方法,但我只知道我做的不对……
-
谢谢你,这有帮助!
标签: php foreach array-unique