要使用PHP的is_array()
函数检查一个变量是否为数组,只需将该变量作为参数传递给函数
<?php
$variable1 = array("apple", "banana", "cherry");
$variable2 = "This is a string";
if (is_array($variable1)) {
echo "Variable 1 is an array.";
} else {
echo "Variable 1 is not an array.";
}
if (is_array($variable2)) {
echo "Variable 2 is an array.";
} else {
echo "Variable 2 is not an array.";
}
?>
在这个例子中,$variable1
是一个数组,所以输出结果是"Variable 1 is an array.“。而$variable2
是一个字符串,所以输出结果是"Variable 2 is not an array.”。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:使用is_array检查变量是否为数组