In what ways can a beginner in PHP effectively manage session variables for individual questions in a script?

When managing session variables for individual questions in a script, beginners in PHP can effectively use unique session keys for each question. This ensures that the session variables are distinct and can be easily accessed and updated as needed.

// Start the session
session_start();

// Set a unique session key for each question
$question1 = 'What is your name?';
$question2 = 'How old are you?';

// Store user responses in session variables
$_SESSION['answer1'] = $_POST['answer1'];
$_SESSION['answer2'] = $_POST['answer2'];

// Retrieve and display stored answers
echo 'Answer to question 1: ' . $_SESSION['answer1'];
echo 'Answer to question 2: ' . $_SESSION['answer2'];