【问题标题】:get value from form input and save in to array 2D从表单输入中获取值并保存到二维数组
【发布时间】:2020-04-09 17:38:12
【问题描述】:

我想将输入值保存到二维数组中。

<table>
  <?php
    $kriteria = array('IP', 'SE', 'PE', 'BE');

  ?>
    <thead>
      <tr>
        <th>Kriteria</th>
        <?php
           foreach ($kriteria as $val) {
              echo '<th>' . $val . '</th>';
           }
        ?>
      </tr>
    </thead>
    <tbody>
      <?php $n = count($kriteria); ?>
      <?php for ($i = 0; $i < $n; $i++): ?>
      <tr>
        <th>
          <?= $kriteria[$i] ?>
        </th>
        <?php for ($j = 0; $j < $n; $j++): ?>
        <td><input type="text" class="form-control" id="<?= $kriteria[$j] . $kriteria[$i] ?>" name="<?= $j. $i ?>" value=""></td>
        <?php endfor; ?>
      </tr>
      <?php endfor; ?>
    </tbody>
</table>

我尝试了POST 方法,但没有成功。

我想使用输入中的值在另一个页面中计数。

这是结果

【问题讨论】:

  • 当你说我尝试了POST 方法你到底尝试了什么?

标签: php html arrays forms input


【解决方案1】:

我想使用输入中的值在另一个页面中计数。

public function page1()
{
    $kriteria = json_encode(array('IP', 'SE', 'PE', 'BE'));
    $temp = sys_get_temp_dir() . '/tmp_file_123';
    file_put_contents($temp, $kriteria);
}

public function page2()
{
    $temp = sys_get_temp_dir() . '/tmp_file_123';
    $kriteria = file_get_contents($temp);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多