如何在PHP中判断数组类型
导读:在 PHP 中,可以使用 is_array( 函数来判断一个变量是否为数组类型 <?php $array = array("apple", "banana", "cherry" ; $notArray = "This is not...
在 PHP 中,可以使用 is_array() 函数来判断一个变量是否为数组类型
<
?php
$array = array("apple", "banana", "cherry");
$notArray = "This is not an array.";
if (is_array($array)) {
echo "The variable '\$array' is an array.";
}
else {
echo "The variable '\$array' is not an array.";
}
if (is_array($notArray)) {
echo "The variable '\$notArray' is an array.";
}
else {
echo "The variable '\$notArray' is not an array.";
}
?>
上述代码将输出:
The variable '$array' is an array.
The variable '$notArray' is not an array.
通过使用 is_array() 函数,您可以判断给定的变量是否为数组类型。如果该变量是数组,则函数返回 true;否则,返回 false。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何在PHP中判断数组类型
本文地址: https://pptw.com/jishu/698832.html
