in_array 检查数组中是否存在某个值 &reftitle.description; boolin_array mixedneedle arrayhaystack boolstrict&false; 大海捞针,在大海(haystack)中搜索针(needle),如果没有设置 strict 则使用宽松的比较。 &reftitle.parameters; needle 待搜索的值。 如果 needle 是字符串,则比较是区分大小写的。 haystack 待搜索的数组。 strict 如果第三个参数 strict 的值为 &true; 则 in_array 函数还会检查 needle类型是否和 haystack 中的相同。 在 PHP 8.0.0 之前,string needle 在非严格模式下将会匹配数组中的值 0,反之亦然。这可能会导致不希望的结果。其它类型也存在类似的边缘情况。如果不是绝对确定有关值的类型,请始终使用 strict flag 以避免意外行为。 &reftitle.returnvalues; 如果找到 needle 则返回 &true;,否则返回 &false;。 &reftitle.examples; <function>in_array</function> 示例 ]]> 第二个条件失败,因为 in_array 是区分大小写的,所以以上程序显示为: <function>in_array</function> 严格类型检查示例 ]]> &example.outputs; <function>in_array</function> 中用数组作为 needle ]]> &example.outputs; &reftitle.seealso; array_search isset array_key_exists