在下表中,$count1
是一个数值。如何按$count1
降序对表进行排序?
$words = explode(" ", $commentstring);
$result = array_combine($words, array_fill(0, count($words), 0));
foreach($words as $word) {
$result[$word]++;
}
echo "<table>";
foreach($result as $word => $count1) {
echo '<tr>';
echo '<td>';
echo "$word";
echo '</td>';
echo '<td>';
echo "$count1 ";
echo '</td>';
echo '</tr>';
}
echo "</table>";
答案 0 :(得分:1)
你也可以使用sort($array_var, SORT_DESC);
http://us.php.net/manual/en/function.sort.php
编辑:
用法
$foo = array('bar', 'car', 'apple', 'food', 'banana');
sort($foo, SORT_DESC);
答案 1 :(得分:1)
此行后asort()
$words = explode(" ", $commentstring);
asort($words);
答案 2 :(得分:0)
感谢响应者......他们引导我朝着正确的方向前进。我终于得到了这个工作:
foreach($words as $word) {
$result[$word]++;
arsort($result);
}