How can the code snippet be improved to handle the unset($_SESSION) operation more effectively when the guessed number matches the generated number?

The issue with the current code snippet is that unsetting the entire $_SESSION array using unset($_SESSION) after the guessed number matches the generated number can lead to unintended consequences, such as losing other session data. To handle this more effectively, we can unset only the specific session variable related to the guessed number. This can be achieved by using unset($_SESSION['guess']) instead of unset($_SESSION).

<?php
session_start();

$min = 1;
$max = 10;
$generated_number = rand($min, $max);

if(isset($_POST['submit'])) {
    $guess = $_POST['guess'];
    
    if($guess == $generated_number) {
        echo "Congratulations! You guessed the correct number.";
        unset($_SESSION['guess']); // Unset only the 'guess' session variable
    } else {
        echo "Try again!";
        $_SESSION['guess'] = $guess;
    }
}
?>

<form method="post">
    <label for="guess">Guess a number between 1 and 10:</label>
    <input type="number" name="guess" id="guess" required>
    <button type="submit" name="submit">Submit</button>
</form>