简体   繁体   English

在循环中以周期性形式向我的字段添加字符

[英]add character to my field in form periodic in a loop

i need a php code that user click on send button in my form automatically add a different character like a - b - c -d to field input.我需要一个 php 代码,用户单击表单中的发送按钮会自动将不同的字符(如 a-b-c-d)添加到字段输入中。 for example this is my form html code.例如,这是我的表单 html 代码。

<form action="action.php" method="post">

  <input type="text" id="phone" name="phone">
 <input type="submit" value="send">
</form>

and in action.php like this在 action.php 中像这样

  echo $_POST['phone'];

user enter 002255 in phone number field and click send button print 002255 now .用户在电话号码字段中输入 002255,然后单击发送按钮立即打印 002255。

but i want when user click send button for first time , print a002255 and when click send button for second time , print b002255 and next c002255 and next d002255 then make a loop and when click for fifth time , print a002255 again.但我想当用户第一次单击发送按钮时,打印 a002255,当第二次单击发送按钮时,打印 b002255 和下一个 c002255 和下一个 d002255 然后循环,当第五次单击时,再次打印 a002255。

What will happened after reaching letter Z?到达字母 Z 后会发生什么? In example below it will reset.在下面的示例中,它将重置。 I think you need to create an array and index to it.我认为您需要创建一个数组并对其进行索引。 So when user click button index goes +1.因此,当用户单击按钮索引变为 +1 时。 Index will be on session because it has to store number.索引将在会话中,因为它必须存储数字。 Am beginner too and trying to figure it out.我也是初学者,并试图弄清楚。 Example:例子:

session_start();
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

if(isset($_POST["submit"])) {

    if($_SESSION["Number"] == 0) {
        print_r($alphabet[0] . "002255");
        $_SESSION["Number"] += 1;
    } else {
        print_r($alphabet[$_SESSION["Number"]] . "002255");
        $_SESSION["Number"] += 1;

        if($_SESSION["Number"] > 26) {
            $_SESSION["Number"] = 0;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM