我有以下代碼:in_array返回false時,它應該返回true
$stopwords = file("/path/to/my-file.txt", FILE_IGNORE_NEW_LINES);
echo($stopwords[0]." - ");
$words = explode(" ", "alors on danse");
echo($words[0]." - ");
if (in_array($words[0], $stopwords)) {
echo("yay");
} else {
echo("nay");
}
,我總是得到alors - alors - nay
結果,當我期待alors - alors - yay
我見過幾個主題在這裏關於類似的問題,並且解決方案几乎總是在列表數組的元素上使用trim()函數。我嘗試過,但它沒有改變任何東西。
你能幫我意識到我在做什麼錯嗎?
什麼是「停用詞」? – egig
您可以顯示'$ stopwords'並且其中包含'alors'嗎? – newfurniturey
'$ stopwords'在哪裏? – SmokeyPHP