PHP program outputs the $response twice after the user has inputted their answer

the program that I’ve made has been bugging me for several days now and I really can’t fix it.
Here’s my code:

include 'generate_word.php';

if (!isset($_SESSION['chat_history']))
{
    $_SESSION['chat_history'] = array();
}

$num_words_generated = isset($_SESSION['num_words_generated']) ? $_SESSION['num_words_generated'] : 0;

if ($num_words_generated <= 10)
{
    $random_word_jumbled = str_shuffle($currentWord);
    $_SESSION['num_words_generated'] =+ $num_words_generated;
    $item_num = $_SESSION['num_words_generated'];

This is the one that’s been appearing twice

    $response = "<div id = 'output-container'><p>Question #" . $item_num . "<br>Unscramble the word: <strong>" . $random_word_jumbled . "</strong></p></div>";
    if (end($_SESSION['chat_history']) != $response)
    {
        array_push($_SESSION['chat_history'], $response);
    }
}else{

And this too

    $response = "<div id = 'output-container'><p>You have finished the quiz!<br>Go back to <a class = 'button' href = 'home.php'>home page.</a></p></div>";
    if (end($_SESSION['chat_history']) != $response)
    {
        array_push($_SESSION['chat_history'], $response);
    }
}

I’m hoping someone could give me some advice. Thanks in advance!