在PHP中is_array的用法实例
导读:在PHP中,is_array( 函数用于检查给定的值是否是一个数组 示例1:检查字符串是否为数组 $str = "Hello, World!"; if (is_array($str { echo "The given value...
在PHP中,is_array()函数用于检查给定的值是否是一个数组
示例1:检查字符串是否为数组
$str = "Hello, World!";
if (is_array($str)) {
echo "The given value is an array.";
}
else {
echo "The given value is not an array.";
}
// 输出:The given value is not an array.
示例2:检查整数是否为数组
$num = 42;
if (is_array($num)) {
echo "The given value is an array.";
}
else {
echo "The given value is not an array.";
}
// 输出:The given value is not an array.
示例3:检查多维数组是否为数组
$multi_dim_array = array(
"name" =>
"John",
"age" =>
30,
"city" =>
"New York"
);
if (is_array($multi_dim_array)) {
echo "The given value is an array.";
}
else {
echo "The given value is not an array.";
}
// 输出:The given value is an array.
示例4:检查对象是否为数组
class Person {
public $name;
public $age;
}
$person = new Person();
$person->
name = "John";
$person->
age = 30;
if (is_array($person)) {
echo "The given value is an array.";
}
else {
echo "The given value is not an array.";
}
// 输出:The given value is not an array.
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 在PHP中is_array的用法实例
本文地址: https://pptw.com/jishu/698827.html
