$country='ID';
echo '$country:' . $country;
echo "\n arCountry: ";
print_r ($arCountry);
echo "\n" . 'in_array($country,$arCountry): ';
echo in_array($country,$arCountry);
结果:
$country:ID
arCountry: Array
(
[0] => UK
[1] =>
US
[2] =>
ID
)
in_array($country,$arCountry):
显然$arCountry
包含ID
然而in_array($country,$arCountry)
:只是空的
答案 0 :(得分:4)
如果您不想在$arCountry
中清理数据,可以尝试将其映射到更有用的内容
in_array($country, array_map('trim', $arCountry))