溫馨提示×

php array_key_exists能檢查多維數組嗎

PHP
小樊
94
2024-11-23 22:27:33
欄目: 編程語言

是的,array_key_exists 函數可以用于檢查多維數組

<?php
$array = [
    'a' => [
        'b' => 'value1',
        'c' => 'value2',
    ],
    'd' => [
        'e' => 'value3',
        'f' => 'value4',
    ],
];

// 檢查多維數組中是否存在指定的鍵
if (array_key_exists('a.b', $array)) {
    echo "Key 'a.b' exists in the array.";
} else {
    echo "Key 'a.b' does not exist in the array.";
}

if (array_key_exists('d.e', $array)) {
    echo "Key 'd.e' exists in the array.";
} else {
    echo "Key 'd.e' does not exist in the array.";
}
?>

在這個例子中,array_key_exists('a.b', $array) 將返回 true,因為鍵 'a.b' 存在于數組中。同樣,array_key_exists('d.e', $array) 也將返回 true,因為鍵 'd.e' 存在于數組中。

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