在联接中达到限制后显示"and X more"

  • 本文关键字:显示 and more php
  • 更新时间 :
  • 英文 :


我有一个帖子的点赞表,我想显示喜欢它的用户。我要做的是让它出现在前 5 个人面前,然后它应该显示and X more people liked this post.我还能够在数组中获取剩余的用户,而不仅仅是拥有它们的数量。

$array = array();
foreach($this->forums_model->get_topic_likes($top->id) as $likes) { 
    $array[] = "<a href=''>" . $this->user_model->get_username($likes["user_id"]) . "</a>";
}
$count = $this->forums_model->count_topic_likes($top->id);
echo join(' and ', array_filter(array_merge(array(join(', ', array_slice($array, 0, ($count - 2)))), array($count - 5 . " more people like this post")), 'strlen'));

这并不完全像我想要的那样工作,并且想知道如何实现这一目标。

选择数组中的所有喜欢,然后只显示前 5 个,并显示 array.length - 5 作为剩余计数。

相关内容

最新更新