<?php
// 定义一个数组
$fruits = array("apple", "banana", "orange");
// 要查找的元素
$searchElement = "banana";
// 使用 in_array 函数判断数组中是否包含某个元素
if (in_array($searchElement, $fruits)) {
echo "数组中包含元素: " . $searchElement;
} else {
echo "数组中不包含元素: " . $searchElement;
}
?>
in_array
是 PHP 内置函数,用于检查数组中是否存在指定的值。$fruits
是我们要检查的数组。$searchElement
是我们要查找的元素。Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站