可以使用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 asinh() 函数返回一个数的反双曲正弦。
下一篇:php如何写二维数组
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站