分配值后使用PHP变量

时间:2013-09-11 22:40:59

标签: php forms

我有一份表格和评论我也在加价。现在代码如下,工作正常

HTML

<select name="DriverShaft" class="select">
  <option value="" selected="selected">Select Shaft</option>
  <option value="LE- light weight graphite weakest flex : 5.00">LE- light weight graphite weakest flex</option>
  <option value="LW- Light weight graphite weak flex : 5.00">LW- Light weight graphite weak flex</option>
  ....
  <option value="DX- Heavy weight steel extra stiff : 15.00">DX- Heavy weight steel extra stiff</option>
  <option value="DS- Heavy weight steel stiff flex : 15.00">DS- Heavy weight steel stiff flex</option>
</select>

php在评论部分获取轴名称和价格(如果已选择)

if (!empty($_REQUEST['DriverShaft'])) {
    list($shaft, $price) = explode(":", $_REQUEST['DriverShaft']);
    echo "<div class='reviewItem'><span class='reviewTitle'>Shaft:</span>{$shaft}</div>";
    echo "<div class='reviewItem'><span class='reviewTitle'>Price:</span>{$price}</div>";
} else echo "";

我的问题是,我list($shaft, $price) = explode(":", $_REQUEST['DriverShaft']);可以在任何地方调用$price后返回该值吗?我问,因为我想在最后制作一个数组,并从以下选项中加起来价格:

$total = array($price, $anotherprice);
echo "sum(a) = " . array_sum($total) . "\n";

0 个答案:

没有答案