【问题标题】:make view of array with filling input in the form在表单中填充输入以查看数组
【发布时间】:2019-11-16 12:38:08
【问题描述】:

我想创建一个数组视图,首先我需要为第一个表单填充数组的长度(这是显示多少),然后我用它来填充数组的值,然后我显示它。

<form method="POST" action="prak_9_1.php">
input length of array <input type="text" name="bilangan">
<input type="submit" value="Hasil">

第二个代码是不同的文件

    <?php
    $bilangan = $_POST['bilangan'];
    $bil = $bilangan;
    $array = array();
    $n = 0;
    ?>
    <form method="POST" action="prak_9_1.php">
    <?php
    for ($i=0; $i < $bilangan ; $i++) { 
    echo "input value of array : <input type='text' name='nilai_".$i."'><br>";
    }
    ?>
    <input type="submit" value="Hasil">
    </form>
    <?php

    for ($i=0; $i < $bil ; $i++) { 
    $array[$n] = $_POST['nilai_'.$i];
    $n++; 
    }
    print_r($array);?>

对不起,如果我的英语不好...感谢您的帮助...

【问题讨论】:

    标签: php arrays forms


    【解决方案1】:

    第一个文件:

    <form method="POST" action="second.php">
        input length of array <input type="text" name="bilangan">
        <input type="submit" value="Hasil">
    </form>
    

    第二个文件:

    <?php
    if (isset($_POST['bilangan'])) {
        echo '<form method="POST">';
        for ($i = 0; $i <= $_POST['bilangan']; $i++) {
           echo "input value of array : <input type='text' name='nilai[]'><br>";
        }
        echo '<input type="submit" value="Hasil">';
        echo '</form>';
    }
    
    if (isset($_POST['nilai'])) {
        print_r($_POST['nilai']);
    }
    ?>
    

    【讨论】:

    • 没有任何解释的代码转储很少有帮助(尤其是当 OP 明确表示这是一个家庭作业问题时)。 Stack Overflow 是关于学习的,而不是提供 sn-ps 来盲目复制和粘贴。请edit您的问题并解释它如何比OP提供的更好。
    猜你喜欢
    • 2015-03-30
    • 2017-09-13
    • 1970-01-01
    • 2018-03-08
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    相关资源
    最近更新 更多