为什么停止删除单词是空的? (PHP)

I'm the beginner NLP programmer in PHP. I just want to discuss about the stop word removal.

this is my practice:

I have the following declaration of a variable $words = "he's the young man";

and then I remove the common words like this

 $common_words = $this->common_words();
 $ncwords = preg_replace('/\b('.implode('|',$common_words).')\b/','',$data); 
 // I have save the array common_words in another function

and I explode my no common words

$a_ncwords=explode(" ", $ncwords);

But, when I print $a_ncwords, like so print_r($a_ncwords);

I get a result like this:

Array ( [0] => [1] => [2] => young [3] => man )

why are the index[0] and index[1] array values null?

Remove the empty array elements.

To appease those who said it didn't answer your question:

Your preg_replace is replacing words with null and when you explode because your regex is off, those null values are getting created in your array $a_ncwords when you explode.

$a_ncwords = array_filter($a_ncwords);

Because you are replacing the words with an empty string. The array elements still exist, they are just empty now.

You should remove them from the array if they are empty. You can do this like so:

array_filter($ncwords, function($item) { return !is_null($item); });