我是 PHP 的新手,所以如果这太简单和明显,我很抱歉。
我有一个网络表单,用户可以动态添加输入字段。当用户单击提交时,所有输入字段都会保存到一个数组中。当我使用 print_r 命令时,我得到一个如下所示的数组:
Array
(
[1] => Array ( [tc] => 00:10 [feedback] => good )
[2] => Array ( [tc] => 00:20 [feedback] => bad )
[3] => Array ( [tc] => 00:21 [feedback] => Bigger text )
)
我用来将数据拉入数组的代码是:
if (!empty($_POST)) { //The values have been posted
$elements = array();
foreach ($_POST as $key => $val) { //For every posted values
$frags = explode("_", $key); //we separate the attribute name from the number
$id = $frags[1]; //That is the id
$attr = $frags[0]; //And that is the attribute name
if (!empty($val)) {
//We then store the value of this attribute for this element.
$elements[$id][$attr] = htmlentities($val);
}
}
}
我想显示数据的方式是这样的:
01: 00:10 - good<br />
02: 00:20 - bad<br />
03: 00:21 - Bigger text<br />
我正在尝试制作的表格可以在http://ridefreemedia.com.au/test找到