阅读量:0
要使用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.”。