2012-12-05 51 views
2

我的表单上有一个隐藏字段,我想整理并发布与数组中的价格相关的日期,以便我可以在另一个页面上使用它们。目前,我有以下定义的输入字段。输入字段内的多维数组

<input name="arrayDatesPrices[]" type="hidden" 
value="<?php echo PrintDateTime($recordsCourseWeeks->getField('Start_date'),"d/m/Y"); ?>"> 

当我在接下来的页面上执行print_r(arrayDatesPrices)时,它列出了数组中的所有日期。这完全按照预期工作。我有另一个名为$ Price_per_week的字段,我想将价格与日期关联。因此我尝试了以下内容。

<input name="arrayDatesPrices[]" type="hidden" 
value="<?php echo array(PrintDateTime ($recordsCourseWeeks->getField('Start_date'),"d/m/Y"), array($Price_per_week)); ?>"> 

当我在下面的页面上做一个print_r(arrayDatesPrices) - 我得到一个空白数组。我有我的格式不正确,或者你可以做多维数组输入字段?

+0

尝试通过会话转移这些东西呢? – hakazvaka

+0

你正在做<?php echo array(); ?>在你的代码中。它导致将数组转换为字符串,从而导致value =“Array”。如果你需要整个数组的内部值属性,你可以print_r($ array,true)。 –

回答

0
Try like this.. 

<input name="arrayDatesPrices[]" type="hidden" 
value="<?php echo PrintDateTime($recordsCourseWeeks->getField('Start_date'), 
"d/m/Y").':'.$Price_per_week ; ?>"> 

After submit... 
$i = 0; 
foreach($arrayDatesPrices as $arr) 
{ 
list($stat,$wk) = explode(':',$arr); 
$new_arr[$i]['start_date'] = $stat; 
$new_arr[$i++]['wek'] = $wk; 
} 
1

也许你可以把这两个值放在字段上;分隔符并在提交后与服务器代码一起爆炸?

还是觉得像其它方式您字段:

<input name="arrayDatesPrices[0][start_date]" type="hidden" value="<?php echo PrintDateTime($recordsCourseWeeks->getField('Start_date'),"d/m/Y"); ?>" /> 
<input name="arrayDatesPrices[0][price_per_week]" type="hidden" value="<?php echo $Price_per_week ?>" /> 

而递增的第一个参数为每一对新人值

2

的您可以使用json_*serialize finctions存储结构。
例如:

<input name="arrayDatesPrices[]" type="hidden" 
value="<?php echo json_encode(PrintDateTime($recordsCourseWeeks->getField('Start_date'),"d/m/Y")); ?>"> 

而且在PHP代码ü必须调用:

$val = json_decode($_REQUEST['arrayDatesPrices'][$i]);