Php 从数组中排除某些单词
下表显示了字符串Php 从数组中排除某些单词,php,Php,下表显示了字符串$commentstring中的所有单词。如何排除某些冠词、介词和动词,如“the、of、is” $words=explode(“,$commentstring); $result=array(); 阿尔索特(大写); foreach($words作为$word){ 如果(!是数字($word)){ $result[$word]++; 阿尔索特(结果); } } 回声“; foreach($word=>$count1的结果){ 回声'; 回声'; 回显“$word”; 回声';
$commentstring
中的所有单词。如何排除某些冠词、介词和动词,如“the、of、is”
$words=explode(“,$commentstring);
$result=array();
阿尔索特(大写);
foreach($words作为$word){
如果(!是数字($word)){
$result[$word]++;
阿尔索特(结果);
}
}
回声“;
foreach($word=>$count1的结果){
回声';
回声';
回显“$word”;
回声';
回声';
回显“$count1”;
回声';
回声';
}
回声“;
有几种方法可以做到这一点,如果您仍然想对它们进行计数,但只是不想在表中显示它们,您可以执行以下操作:
$blacklist = array('the', 'is', 'a');
foreach($result as $word => $count1)
{
if (in_array($word, $blacklist)) continue;
...
如果您甚至不想计数,您可以在计数循环中以类似的方式跳过它们。可能的重复项
$blacklist = array('the', 'is', 'a');
foreach($result as $word => $count1)
{
if (in_array($word, $blacklist)) continue;
...