is_array()
函数在 PHP 中用于检查一个变量是否是数组
如果给定的变量是数组,is_array()
函数将返回 true
,否则返回 false
。
示例:
$array = [1, 2, 3];
$notArray = "This is not an array.";
if (is_array($array)) {
echo "The variable \$array is an array."; // 输出: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 $notArray is not an array.
}