What are potential pitfalls when using session variables in PHP, especially when accessing specific values within an array?

When using session variables in PHP, a potential pitfall is accessing specific values within an array stored in a session variable. To avoid issues, always check if the array key exists before trying to access its value to prevent errors.

// Check if the array key exists before accessing its value
if(isset($_SESSION['user']['name'])){
    $userName = $_SESSION['user']['name'];
    // Use $userName safely
} else {
    // Handle the case where the key doesn't exist
}