Php 如何以独特的方式获取多个表单数据?
我有一个表单,它有两个文本字段。一个是价格,另一个是共享。这些文本字段每行重复一次。我在post数组中提取提交后的值。但是Php 如何以独特的方式获取多个表单数据?,php,codeigniter,Php,Codeigniter,我有一个表单,它有两个文本字段。一个是价格,另一个是共享。这些文本字段每行重复一次。我在post数组中提取提交后的值。但是POST数组以正常方式出现。我希望它在一个具体的方式如下 <td colspan="3"><label><?php echo form_error('amount'); ?></label><input type="text" class="textsmall" name="post_cost[]" id="<?ph
POST
数组以正常方式出现。我希望它在一个具体的方式如下
<td colspan="3"><label><?php echo form_error('amount'); ?></label><input type="text" class="textsmall" name="post_cost[]" id="<?php echo $cust_id_cur; ?>" value="<?php echo set_value('amount'); ?>" /></td>
<td colspan="3"><label><?php echo form_error('share'); ?></label><input type="text" class="textsmall" name="post_share[]" id="<?php echo $cust_id_cur; ?>" value="100" /></td>
但是我想要上面两个这样的数组。有一个名为$cust\u id\u cur
的文件是唯一的文件。我需要每个数组的值与这些id相对应。我的意思是总共有六行,因此将有六个客户id
post_cost
(
[$cust_id_cur] => 324123
[$cust_id_cur] => 324123
[$cust_id_cur] => 324123
[$cust_id_cur] => 324123
[$cust_id_cur] => 324123
[$cust_id_cur] => 324123
)
为什么我这样问是因为我的客户id的顺序不总是一样的。因此,我将针对
客户id
。当我提交时,我需要根据客户id将它们保存在数据库中。因此,我需要如上所示的数组。您可以使用循环中的变量填充索引:
<td colspan="3"><label><?php echo form_error('amount'); ?></label><input type="text" class="textsmall" name="post_cost[<?php echo $cust_id_cur; ?>]" id="<?php echo $cust_id_cur; ?>" value="<?php echo set_value('amount'); ?>" /></td>
^^^^^^^^ here
<td colspan="3"><label><?php echo form_error('share'); ?></label><input type="text" class="textsmall" name="post_share[<?php echo $cust_id_cur; ?>]" id="<?php echo $cust_id_cur; ?>" value="100" /></td>
^^^^^^^^ here
我能想到的最简单的方法是array\u map
。
<td colspan="3"><label><?php echo form_error('amount'); ?></label><input type="text" class="textsmall" name="post_cost[<?php echo $cust_id_cur; ?>]" id="<?php echo $cust_id_cur; ?>" value="<?php echo set_value('amount'); ?>" /></td>
^^^^^^^^ here
<td colspan="3"><label><?php echo form_error('share'); ?></label><input type="text" class="textsmall" name="post_share[<?php echo $cust_id_cur; ?>]" id="<?php echo $cust_id_cur; ?>" value="100" /></td>
^^^^^^^^ here