对于计算总金额的变量,我该怎么用?
例如
if ($featured == "1"){
$cost = 100;
}else{
$cost = 1000;
}
基本上每次循环时,我们都会在页面上显示$cost
,但我还想留出一个变量$total
,在循环运行时将每个$cost
相加。 / p>
答案 0 :(得分:1)
对不起,但是真的吗?
$total = 0; // this somewhere before the loop
// start loop
if ($featured == "1") {
$cost = 100;
} else {
$cost = 1000;
}
$total += $cost;
// end loop