是的,PHP 的 in_array() 函数可以处理 null 值。如果数组中包含一个 null 值,in_array() 函数仍然会返回 true。这是因为 in_array() 在比较数组元素时,会将 null 值视为等于另一个 null 值。
示例:
$array = [1, 2, null, 4]; if (in_array(null, $array)) { echo "Null value found in the array."; } else { echo "Null value not found in the array."; } 输出:
Null value found in the array.