对不起这个愚蠢的问题。我想花费 25 个积分,我的可用积分是 30(10,10,10)。但在我下面的示例代码中,最终数量是减(-)5 值而不是 5。请检查我的代码、实际输出和我的预期结果:
代码:
<?php
$content_credit = 25;
$data = array(10,10,10);
$used_credit = 0;
for($i=0; $i<count($data); $i++){
if($content_credit > $used_credit){
$used_credit += $data[$i];
echo "Point: " . $data[$i];
echo " Used: " . $used_credit;
echo " Remaining: " . ($content_credit - $used_credit);
}
echo "<br>";
}
实际结果:
Point: 10 Used: 10 Remaining: 15
Point: 10 Used: 20 Remaining: 5
Point: 10 Used: 30 Remaining: -5
预期结果:
Point: 10 Used: 10 Remaining: 15
Point: 10 Used: 20 Remaining: 5
Point: 10 Used: 25 Remaining: 5
慕桂英4014372
PIPIONE
蝴蝶不菲