每次我按下提交我想要输入文本框更改文本

Each time I press submit I want input text box change text

所以基本上我有一个简单的表单,我想在每次使用 PHP 按下提交时更改不同的输入框文本。我知道我的代码不起作用,但我不明白如何解决这个问题。也许数组不是最好的方法?

<body>
    <?php 
        if(isset($_GET['submit'])) exit();
        $msg= ['One', 'Two', 'Three', '']
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']?>">
    <input type="submit" name="submit" value="Paina nappi">
    <input type="text" name="msg" value="<?php echo (isset($msg)) ? $viesti : ''; ?>">
    </form>
</body>

你可以这样写:

<?php
    session_start();

    $msgArray= array('One', 'Two', 'Three', '');
    // if $_SESSION['msgIndex'] is not set, we initialize it, or it will take 0 value every loading page
    if (!isset($_SESSION['msgIndex'])) { $_SESSION['msgIndex'] = 0;  }

    if (isset($_GET['submit'])) {
        getMessage();
    }

    // We save msgIndex in a $_SESSION variable cause even if the user reload the page, we keep the value
    function getMessage() {
        if ($_SESSION['msgIndex'] >= 0) {
            $_SESSION['msgIndex'] += 1;
        } if ($_SESSION['msgIndex'] > 3) {
            $_SESSION['msgIndex'] = 0;
        }
    }
?>

<form action="<?php echo $_SERVER['PHP_SELF']?>">
    <input type="submit" name="submit" value="Paina nappi">
    <input type="text" name="msg" value="<?= $msgArray[$_SESSION['msgIndex']] ?>">
</form>