How can the session ID be utilized effectively in PHP to store multiple values?

When using session IDs in PHP, you can store multiple values by creating an associative array and storing it in the session variable. This allows you to store multiple key-value pairs within the session data, making it easy to retrieve and manipulate the values as needed.

// Start the session
session_start();

// Create an associative array to store multiple values
$sessionData = array(
    'username' => 'john_doe',
    'email' => 'john.doe@example.com',
    'role' => 'admin'
);

// Store the array in the session variable
$_SESSION['userData'] = $sessionData;

// Retrieve and access the values stored in the session
$username = $_SESSION['userData']['username'];
$email = $_SESSION['userData']['email'];
$role = $_SESSION['userData']['role'];

// Output the values
echo "Username: $username<br>";
echo "Email: $email<br>";
echo "Role: $role";