如何把循环中的内容逐个相加

wenfei307 2013-02-25 09:22:34

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,这样的话应该怎么写?
...全文
1026 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ayzen1988 2013-02-25
  • 打赏
  • 举报
回复
循环外定义一个变量初始值为0 $total = 0; 循环体内一直加$total_price $total += $total_price;
红KING 2013-02-25
  • 打赏
  • 举报
回复
$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"; }

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧