我不小心在点击后的答案。 downvotes可以等到我完成吗?
在PHP中,得到的post
中的所有值的数组,这样你才会有:
Array (
blabla #one
wew #two
nice #one
great #one
excellent #one
)
现在,使用implode(" ", $posts)
加入所有的数组项,这给你一个字符串:
blabla #one wew #two nice #one great #one excellent #one
分割使用explode(" ", $posts)
。现在,检查以#
开头的值。将它们添加为数组索引并增加计数!现在,你有增加计数的代码!现在,你可以这样做:
<?php
$posts = explode(" ", "blabla #one wew #two nice #one great #one excellent #one");
$rank = array();
foreach ($posts as $post)
if (strpos("#", $post))
if (!isset($rank[$post]))
$rank[$post] = 1;
else
$rank[$post]++;
?>
甚至可以通过这样的方式来使用功能array_count_values($hashes)
:
<?php
$posts = explode(" ", "blabla #one wew #two nice #one great #one excellent #one");
$hashes = array();
foreach ($posts as $post)
if (strpos("#", $post))
$hashes[] = $post;
?>
而现在使用array_sort()
或东西由降序对数组进行排序,并用它排名!
Downvoters,你能检查并恢复那些吗?
有没有在每个'POST'只有一个主题标签? – Barmar 2014-09-01 10:29:53
这取决于用户更新帖子。所以我不能说它只有一个#标签 – hiDayurie 2014-09-01 10:32:09