Home>
As "require_once ('config_post.php');" in "test.php"
The following config_post.php is loaded.

// config_post.php
<? php
    $name = $_POST ['name'];
    $subject = $_POST ['subject'];
    $naiyou = $_POST ['naiyou'];
    $tantou = $_POST ['tantou'];
    $ren1 = $_POST ['ren1'];
              ~
    $ren50 = $_POST ['ren50'];

The above is working.
$ren1-$ren50 and 50, but there is a possibility that it will increase more in the future.
What should I do in such cases?
I tried the following as an iterative process, but it didn't work.

// config_post.php
<? php
    $name = $_POST ['name'];
    $subject = $_POST ['subject'];
    $naiyou = $_POST ['naiyou'];
    $tantou = $_POST ['tantou'];
 $i = 1;
 while ($i<= 50) {
    $ren. "$i" = $_POST ["ren". "$i"];
      $i ++;
 }

$ren."$i"= $_POST ["ren"."$i"];

$"ren". "$i" = $_POST ["ren". "$i"];
$ren. $i = $_POST ["ren". "$i"];
echo $ren. "$i" = $_POST ["ren". "$i"];
echo [$ren. "$i"] = $_POST ["ren". "$i"];
echo ($ren. "$i") = $_POST ["ren". "$i"];

If i have a good method, please let me know.

php
  • Answer # 1

    Pass like an array like this.

    <? php
    ini_set ('display_errors', true);
    error_reporting (E_ALL);
    if (filter_input (INPUT_SERVER, 'REQUEST_METHOD') === 'POST') {
        $posts = filter_input (INPUT_POST, 'post', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
        var_dump ($posts);
    }
    ?>
    <! DOCTYPE HTML>
    <html lang = "en">
        <head>
            <meta charset = "UTF-8">
            <title></title>
        </head>
        <body>
            <form action = "" method = "post">
                <p><input type = "text" name = "post []" /></p>
                <p><input type = "text" name = "post []" /></p>
                <p><input type = "text" name = "post []" /></p>
                <p><input type = "text" name = "post []" /></p>
                <p><input type = "text" name = "post []" /></p>
                <p><button>submit</button></p>
            </form>
        </body>
    </html>