这是我的代码:
<?php
$states = array();
if (($file = fopen("branch.csv", "r")) !== FALSE) {
while (($state = fgets($file)) !== FALSE) {
$states[] = $state;
}
fclose($file);
}
print_r($states);
$searchkeyword = "FLORIDA";
if(in_array($searchkeyword, $states)){
echo "we found " . $searchkeyword . "\n";
} else {
echo "we can't found " . $searchkeyword . "\n";
}
?>
这是结果:
Array
(
[0] => FLORIDA
[1] => CHICAGO
)
we can't found FLORIDA
在我看来一切正常,我可以看到数组的第一个元素是 FLORIDA,但 in_array() 找不到 FLORIDA。我可能错过了一些东西。