$buy_amount = 50;
$amount[0] = 100;
$amount[1] = 150;
$amount[2] = 50;
$test;
$i = $buy_amount;
$arrlength = count($amount);
for ($x = 0; $x < $arrlength; $x++) {
$test = $amount[$x] - $i;
if ($amount[$x] != $test) {
$i = $test;
echo $test;
echo '<br/>';
}
}
我需要做的是,如果我发送的$buy_amount = 50
结果需要像这样减去
例子:
$amount[0] = 50;
$amount[1] = 150;
$amount[2] = 50;
如果我发送$buy_amount = 150
结果需要像这样减去
例子:
$amount[0] = 0;
$amount[1] = 100;
$amount[2] = 50;
在这里我需要做的首先从第一个元素中减去并转到其他元素并从中减去,如果buy_amount
留下更多则像明智的那样转到其他元素