The code below returns a table with a row for every word or number that appears in $commentstring. Each word or number appears as $word in the table below. How can I exclude numbers?
$words = explode(" ", $commentstring);
$result = array_combine($words, array_fill(0, count($words), 0));
arsort($words);
foreach($words as $word) {
$result[$word]++;
arsort($result);
}
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>";
You could use
is_numericto check whether each$wordis a number, and only insert it into your array if it isn’t.Edit: Also, do you really need to sort the array on each increment? Why not just sort it at the end?