在 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。


