What are the potential pitfalls of accessing nested arrays in PHP and how can they be avoided?

Accessing nested arrays in PHP can lead to potential pitfalls such as undefined index errors or notices if the keys do not exist. To avoid these issues, it's important to check if the key exists before accessing it to prevent errors.

// Check if the nested key exists before accessing it
if(isset($nestedArray['key1']['key2'])) {
    $value = $nestedArray['key1']['key2'];
    // Use $value as needed
} else {
    // Handle the case when the key does not exist
}