从表单输入获取值并保存到数组2D中

问题描述 投票:0回答:1

我想将输入值保存到2D数组中。

<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方法,但是没有用。

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

此结果enter image description here

php html arrays forms input
1个回答
0
投票

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

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);
}
© www.soinside.com 2019 - 2024. All rights reserved.