我想在看起来像这样的数组中搜索“一月”或“二月”之类的项目
Array
(
[0] => January
[1] => February
[2] => March
[3] => April
)
这是我到目前为止尝试过的。但不起作用。
if ( in_array("January", $date_array) ) {
echo "Found item in Array";
} else {
echo "Didn't find item in Array";
}
结果:
Didn't find item in Array
这是var_dump()的结果
array(4) {
[0]=>
string(9) "January
"
[1]=>
string(10) "February
"
[2]=>
string(7) "March
"
[3]=>
string(7) "April
"
}
答案 0 :(得分:2)
不知道换行符是从哪里来的,但是您可以使用array_map
将其删除:
$date_array = array_map('trim', $date_array);
// and then use `in_array`