Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数组中排除某些单词_Php - Fatal编程技术网

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;

    ...