- var_dump: documentation ( source)
- max: documentation ( source)
- min: documentation ( source)
<?php
$vouchers = array(
1 => 100,
3 => 150,
5 => 100
);
$discounts = array();
$orders = array(50, 100, 200, 300, 500, 1000);
foreach ($orders as $order) {
echo "order: " . $order . PHP_EOL;
$remainingValue = $order;
foreach($vouchers as $id => $voucher) {
echo "voucher : " . $voucher . PHP_EOL;
$discounts[$order][$id] = 0;
$discount = max (0, min ($remainingValue, $voucher));
$remainingValue -= $discount;
}
}
var_dump($discounts);