How can the array_key_exists() function be used to check for the existence of a key in an array before performing value comparisons in PHP?

When working with arrays in PHP, it is important to check if a specific key exists before trying to access its value to avoid potential errors. The `array_key_exists()` function can be used to determine if a key exists in an array before performing any value comparisons. This helps prevent undefined index errors and ensures that the code runs smoothly without any issues.

// Example of using array_key_exists() to check for the existence of a key in an array
$array = array('key1' => 'value1', 'key2' => 'value2');

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