$settings = [
    'theme' => 'dark',
    'language' => 'en',
    'show_errors' => true
];

if (array_key_exists('language', $settings)) {
    echo 'Language setting is defined.';
} else {
    echo 'Language setting is not defined.';
}

// Output: 'Language setting is defined.'
$colors = ['red', 'green', 'blue'];

if (array_key_exists(1, $colors)) {
    echo "Index 1 exists in the array and its value is: " . $colors[1];
} else {
    echo "Index 1 does not exist in the array.";
}

// Output: Index 1 exists in the array and its value is: green
array_key_exists(mixed $key, array $array): bool
$studentScores = [
    'Alice' => 85,
    'Bob' => 90,
    'Charlie' => 78,
    'David' => 95
];

if (array_key_exists('Bob', $studentScores)) {
    echo "Bob's score is available in the array.";
} else {
    echo "Bob's score is not found in the array.";
}
Output:
// Array to search
$myArray = [
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
    // ... more keys
];

// Keys to check
$keysToCheck = ['key1', 'key2', 'key5', 'key7'];

// Loop through the keys
foreach ($keysToCheck as $key) {
    if (array_key_exists($key, $myArray)) {
        echo "Key '$key' exists in the array." . '<br>';
    } else {
        echo "Key '$key' does not exist in the array." . '<br>';
    }
}
Output:
// Array to search
$myArray = [
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
    // ... more keys
];

// Keys to check
$keysToCheck = ['key1', 'key2', 'key5', 'key7'];

foreach ($keysToCheck as $key) {
    if (isset($myArray[$key])) {
        echo "Key '$key' exists in the array." . '<br>';
    } else {
        echo "Key '$key' does not exist in the array." . '<br>';
    }
}
Output:
$config = [
    'database' => [
        'host' => 'localhost',
        'username' => 'myuser',
        'password' => 'mypassword',
        // ...
    ],
    // ...
];

if (array_key_exists('database', $config) && array_key_exists('username', $config['database'])) {
    echo 'Database information is configured.';
} else {
    echo 'Database information is missing or improperly configured.';
}
Output:
$lang = [
    'en' => [
        'greeting' => 'Hello',
        // ...
    ],
    'es' => [
        'greeting' => '¡Hola',
        // ...
    ],
    // ...
];

$selectedLanguage = 'es'; // User-selected language

if (array_key_exists($selectedLanguage, $lang)) {
    echo $lang[$selectedLanguage]['greeting'];
} else {
    echo "Selected language is not supported.";
}
Output: