How can the isset() function be used to prevent "Undefined index" notices when accessing array elements in PHP?

When accessing array elements in PHP, it is common to encounter "Undefined index" notices if the index being accessed does not exist in the array. To prevent these notices, the isset() function can be used to check if the index exists before attempting to access it. This ensures that the code will only access the index if it is actually defined in the array.

// Example of using isset() to prevent "Undefined index" notices
$array = array('key1' => 'value1', 'key2' => 'value2');

// Check if the index exists before accessing it
if(isset($array['key3'])) {
    echo $array['key3']; // This line will not execute
}

// Check if the index exists before accessing it
if(isset($array['key2'])) {
    echo $array['key2']; // This line will execute and output 'value2'
}