is_array()
is_array()是PHP中的内置函数。函数的作用是:检查变量是否为数组。
语法
1 | is_array($variable_name) |
参数:包含单个参数。
$variable_name:我们要检查的变量。
返回值:它是一个布尔函数,所以当$variable_name是布尔值时返回TRUE,否则为FALSE。
下面的示例演示函数is_array()的工作。
程序1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php // PHP code to demonstrate working of is_array() $variable_name1=67.099; $variable_name2=32; $variable_name3="abc"; $variable_name4=array('A', 'B', 'C'); // $variable_name4 is an array, returns TRUE if (is_array($variable_name4)) echo "array('A', 'B', 'C') is an array . \n"; else echo "array('A', 'B', 'C') is not a array value. \n"; // $variable_name1 is not array, gives FALSE if (is_array($variable_name1)) echo "$variable_name1 is a array value. \n"; else echo "$variable_name1 is not a array value. \n"; // $variable_name2 is not array, gives FALSE if (is_array($variable_name2)) echo "$variable_name2 is a array value. \n"; else echo "$variable_name2 is not a array value. \n"; // $variable_name3 is not array, gives FALSE if (is_array($variable_name3)) echo "$variable_name3 is a array value. \n"; else echo "$variable_name3 is not a array value. \n"; ?> |
输出
1 2 3 4 | array('A', 'B', 'C') is an array . 67.099 is not a array value. 32 is not a array value. abc is not a array value. |
参考