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) を実行すると、空の配列が得られます。書式設定が間違っていますか、それとも多次元配列の入力フィールドを作成できますか?

4

3 に答える 3

2

json_*または関数を使用serializeして構造を格納できます。
例えば:

<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]);
于 2012-12-05T12:20:11.097 に答える
1

Maybe you could just put the two values on the field with a ; separator and explode it with you server code after the submit ?

Or think your fields in an other way like :

<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 ?>" />

And incrementing the first parameter for each couple of values

于 2012-12-05T12:16:25.423 に答える
-1
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;
}
于 2012-12-05T14:37:37.323 に答える