スーパー推測で回答しますけれども・・
例えば次のようなデータがあって、
php
1$rows = [
2 [
3 'name' => "ore",
4 'mail' => "ore@example.com",
5 ],
6 [
7 'name' => "are",
8 'mail' => "are@example.com",
9 ],
10 [
11 'name' => "ure",
12 'mail' => "ure@example.com",
13 ],
14];
次のように表示していて、
html
1<form method="post">
2 <table>
3 <tr>
4 <th>name</th>
5 <th>mail</th>
6 </tr>
7 <?php foreach ($rows as $row): ?>
8 <tr>
9 <td><?= h($row['name']) ?></td>
10 <td><?= h($row['mail']) ?></td>
11 </tr>
12 <?php endforeach; ?>
13 </table>
14 <input type="submit" value="POST!">
15</form>
フォームをサブミットしたときに、$_POST に元の $rows のような構造が入るようにしたい、ということでしょうか?
かなり無理やりですけど、次のようにすればフォームをサブミットしたときに $_POST['rows'] に $rows と同じ構造でデータが入ります。
html
1<form method="post">
2 <table>
3 <tr>
4 <th>name</th>
5 <th>mail</th>
6 </tr>
7 <?php foreach ($rows as $i => $row): ?>
8 <tr>
9 <td><?= h($row['name']) ?><input type="hidden" name="rows[<?=h($i)?>][name]" value="<?= h($row['name']) ?>"></td>
10 <td><?= h($row['mail']) ?><input type="hidden" name="rows[<?=h($i)?>][mail]" value="<?= h($row['mail']) ?>"></td>
11 </tr>
12 <?php endforeach; ?>
13 </table>
14 <input type="submit" value="POST!">
15</form>
退会済みユーザー
2016/02/10 02:29