为什么变量不会连接?

on page reload or submit it should add the guessed word to $guesses and add a pipe. Every time it reloads it should add no replace.I am storing it in a hidden element to keep between page loads, but it does not appear to be working. What am I doing wrong?

<html>
<body>
    <p style='text-align:center;'>
    <?php 
        $wordChoices = array("grape","apple","orange","banana","plum","grapefruit");//Course provided aray/code
        $randChoice;
        $tempVar;
        if(isset($_POST['gu']))
            $guesses=$_POST['gu'];
        else
            $guesses="";
        echo "|||||||||" . $guesses . "||||||||";
        if(empty($_POST['va']))
        {
            $randChoice=rand(0,5);
        }
        else
        {
            $randChoice=$_POST['va'];       
        }   

        //$randChoice = rand(0,5);//NEEDS FIX
        for($i=0;$i<=5;$i++)//output of array and green text
        {
            if($i==$randChoice)
                echo "<span style='color: green; text-align:center;'>$wordChoices[$i]</span>";//prints green word
            else
                echo "<span style='text-align:center;'>$wordChoices[$i]</span>";//print word
            if($i<5)//kills extrta "|"
                echo " | ";//print break between words

        }
    ?>
    </p>
    <h1 style='text-align:center;'>Word guess</h1>
    <div style='text-align:center'>
        <a href='lab1.php'>Refresh This Page</a>
    </div>
    <h3 style='text-align:center;'>Guess the word I'm thinking</h3>
    <form action="<?php $_SERVER['PHP_SELF'];?>" method='POST' style='text-align:center;'>
        <input type='text' name='tb1' placeholder=<?php echo $wordChoices[$randChoice];?>>
        <input type='submit' name='butt'>
        <input type='hidden' name='va' id='va' value="<?php echo $randChoice;?>">
        <input type='hidden' name='gu' id='gu' value="<?php echo $guesses;?>">
    </form>
    <?php 
        if($_POST)
        {
            if(!empty($_POST['tb1']))
            {
                $guesses += $_POST['tb1'] . "|";
            }
            if(isset($_POST['tb1']) && $_POST['tb1'] == $wordChoices[$randChoice])//checks to see if correct
                echo "<p style='text-align:center; color:red;'>You guessed " . $wordChoices[$randChoice]. " and that's CORRECT!!! (3)</p>";//prints out correct
            else if(!isset($_POST['tb1'])||$_POST['tb1']=="")//checks if nothing entered
                echo "<p style='text-align:center; color:red;'>Come on, enter something (2)</p>";//prints out message to enter text
            else if(isset($_POST['tb1']) && isValid($_POST['tb1']) && strtoupper($_POST['tb1'])!=strtoupper($wordChoices[$randChoice]))//checks for valid guess but incorrect term
                echo "<p style='text-align:center; color:red;'>Sorry " . $_POST['tb1'] . " is wrong. Try again (4)</p>";//prints out valid incorrect guess
            else if(isset($_POST['tb1']) && !isValid($_POST['tb1']))//checks if guess is valid
                echo "<p style='text-align:center; color:red;'>Hey, that's not even a valid guess. Try again (5).</p>";//prints out invalid
            echo "<ul>".$guesses."</ul>";
        }
        else 
            echo "<p style='text-align:center; color:red;'>It's time to play the guessing game! (1)</p>";

        function isValid($textResp)//checks is guessed word is a valid word
        {
            print($textResp);
            $wordChoices = array("grape","apple","orange","banana","plum","grapefruit");
            if($textResp==$wordChoices[0])
                return true;
            else if($textResp==$wordChoices[1])
                return true;
            else if($textResp==$wordChoices[2])
                return true;                    
            else if($textResp==$wordChoices[3])                 
                return true;
            else if($textResp==$wordChoices[4])
                return true;
            else if($textResp==$wordChoices[5])
                return true;
            else
                return false;

        }
    ?>
</body>

Unsimilar to Java, C# or similar, operators with + - * will only work on numbers. Strings have the . operator for String concatenation. If you utilize + on a String PHP will type juggle a String to a number. Bottomline use . or .=.

You are using the wrong assignment operator; += is for math, .= is for string concatenation.

Demos:

  1. https://eval.in/647334
  2. https://eval.in/647333

So:

$guesses += $_POST['tb1'] . "|";

should be:

$guesses .= $_POST['tb1'] . "|";

For a break down of all assignment operators see the first user contribution on http://php.net/manual/en/language.operators.assignment.php.