可以使用in_array()函数来判断某个数据是否在数组中。
$data = array("apple", "banana", "orange");
if (in_array("apple", $data)) {
echo "apple is in the array";
} else {
echo "apple is not in the array";
}
输出结果为:apple is in the array
如果要判断的数据不在数组中,输出结果为:apple is not in the array
上一篇:php求数组的平均数
下一篇:php如何写二维数组
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站