溫馨提示×

在PHP中is_array的用法實例

PHP
小樊
100
2024-09-12 11:40:34
欄目: 編程語言

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

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女