我有一個非常簡單的腳本,它讀出一個txt文件,將內容放入數組中。PHP in_array()找不到數組中的內容
這是完美的,我可以做print_r($array)
;並輸出所有的數據。
我的腳本:
<?php
$file = 'countries.txt';
$countries_output = file_get_contents($file);
$countries_pieces = explode("\n", $countries_output);
if (in_array("Sweden", $countries_pieces)) {
echo "Sweden was found";
}
else
{
echo'NOT FOUND';
}
print_r($countries_pieces);
?>
我不明白爲什麼它沒有找到我的數組值「瑞典」,當它顯然是在那裏。
這是輸出:https://pastebin.com/z9rC9Qvk
我也print_r的數組,所以你可以看到,「瑞典」確實在數組中。
希望有人可以幫助:)
太棒了!你搖滾。 – 2012-01-06 15:40:23
是的 - 這裏可能還有一個\ r或其他一些奇怪的東西。 – 2012-01-06 15:40:38
@Godius:如果答案能解決您的問題,請記住將問題標記爲已回答。 – 2012-01-06 18:16:23