这是我的初始代码:
$camp_price=array(
'option 1' => array(
'id' => 'June 30 to July 20',
'weeks' => 3,
'week_price' => 995),
'option 2' => array(
'id' => 'June 30 to July 13',
'weeks'=> 2,
'week_price' => 995)
);
foreach ($camp_price as $name=>$values) {
$total_cost[$name]=$values['weeks'] * $values['week_price'];
}
这是HTML代码。它完美地呼应了 $total_cost 直到表单被提交。然后它显示错误:
警告:非法字符串偏移“选项 1”
我不明白:
<select name="preferred_session">
<option value="option 1" <?php if($preferred_session =='option 1') echo'selected="selected"'; ?>>
<?php echo $camp_price['option 1']['id'],': ', $total_cost['option 1']; ?>euros
</option>
<option value="2" <?php if($preferred_session =='option 2') echo 'selected="selected"'; ?>>
<?php echo $camp_price['option 2']['id'],': ', $total_cost['option 2']; ?>euros
</option>
</select>