I am making a number guessing game, where the person guesses different numbers until they guess the correct number, I want to record these different guesses into an array using the same variable but it only records the most recent guess, is there a way so that it records all guesses in this array?
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$_SESSION['incorrect'] = array();
if(isset($_POST['submit'])){
if(1 <= $_POST['guess'] && $_POST['guess'] <= 100){
$guess = $_POST['guess'];
if($guess < $number){
echo "Your Number is Too Low";
$_SESSION['guesses']++;
array_push($_SESSION['incorrect'], $guess);
} elseif($guess > $number){
echo "Your Number is Too High";
$_SESSION['guesses']++;
array_push($_SESSION['incorrect'], $guess);
} else {
echo "Good Job <br>";
echo $_SESSION['guesses']. "<br>";
print_r($_SESSION['incorrect']);
}
}else {
echo "Please Enter a Number Between 1 and 100";
}
}