开发者

php looping to add up a sum?

What do I use for a variable which will count the total amount?

For example

if ($featured == "1"){
    $cos开发者_StackOverflow社区t = 100;
}else{
    $cost = 1000;
}

Basically each time that is looped, we display the $cost on page, but I also want to set aside a variable $total which adds up each $cost as the loop runs.


I'm sorry, but really?

$total = 0; // this somewhere before the loop

// start loop
if ($featured == "1") {
    $cost = 100;
} else {
    $cost = 1000;
}

$total += $cost;
// end loop
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜