How can the array_key_exists function be effectively utilized in PHP to avoid errors related to undefined offsets?

When accessing array elements by key in PHP, it's important to check if the key exists before trying to access it. This helps avoid errors related to undefined offsets, which can occur when trying to access a key that doesn't exist in the array. The `array_key_exists` function can be used to check if a specific key exists in an array before attempting to access it.

// Check if the key 'example_key' exists in the $array
if (array_key_exists('example_key', $array)) {
    // Access the value associated with 'example_key'
    $value = $array['example_key'];
    // Do something with $value
} else {
    // Handle the case where 'example_key' does not exist in the array
}