当前位置: 代码迷 >> PHP >> 怎么把循环中的内容逐个相加
  详细解决方案

怎么把循环中的内容逐个相加

热度:42   发布时间:2016-04-28 21:59:52.0
如何把循环中的内容逐个相加

for($counter=$i; $counter>=1; $counter--){
$weight="weight_$counter";
$single_price="single_price_$counter";
$total_price="$_POST[$weight]"*"$_POST[$single_price]";
$id="id_$counter";
}
$big_total_price=$total_price+.......;


大概意思就是把每一次for循环中的$total_price进行相加,最后得出来一个总的$big_total_price,这样的话应该怎么写?

------解决方案--------------------
$big_total_price=0;
for($counter=$i; $counter>=1; $counter--){
            $weight="weight_$counter";
            $single_price="single_price_$counter";
            $big_total_price+="$_POST[$weight]"*"$_POST[$single_price]";
            $id="id_$counter";
        }
  相关解决方案