开发者

php looping to add up a sum?

开发者 https://www.devze.com 2023-02-17 07:36 出处:网络
What do I use for a variable which will count the total amount? For example if ($featured == \"1\"){ $cos开发者_StackOverflow社区t = 100;

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

精彩评论

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

关注公众号