How can the $_SESSION superglobal array be used to store session data in PHP?

To store session data in PHP using the $_SESSION superglobal array, you can simply assign values to keys within the $_SESSION array. This data will persist across multiple pages as long as the session is active. To start a session, you need to call session_start() at the beginning of your script.

<?php
// Start the session
session_start();

// Store data in the session
$_SESSION['username'] = 'john_doe';
$_SESSION['email'] = 'john@example.com';

// Retrieve data from the session
$username = $_SESSION['username'];
$email = $_SESSION['email'];

// Output the stored data
echo "Username: $username <br>";
echo "Email: $email";
?>