是的,inarray() 函数可以简化。在 PHP 中,你可以使用 in_array() 函数来检查一个值是否存在于一个数组中。这个函数比 inArray() 更常用,也是 PHP 的内置函数。
in_array() 的基本语法如下:
in_array(value, array, strict);
参数说明:
- value:必需。要在数组中搜索的值。
- array:必需。要搜索的数组。
- strict:(可选)一个布尔值,指定是否使用严格比较。如果设置为- true,则函数将检查- value和- array中的元素是否完全相等(包括类型)。默认值为- false。
示例:
<?php
$array = array("apple", "banana", "orange");
if (in_array("banana", $array)) {
    echo "Banana found in the array.";
} else {
    echo "Banana not found in the array.";
}
?>
这个示例将输出 “Banana found in the array.”,因为 “banana” 存在于 $array 中。

 便宜VPS测评
便宜VPS测评










