3v4l.org

run code in 300+ PHP versions simultaneously
<?php $vouchers = array( 1 => 100, 3 => 150, 5 => 100 ); $discounts = array(); $orders = array(50, 100, 200, 300, 500, 1000); foreach ($orders as $order) { $remainingValue = $order; foreach($vouchers as $id => $voucher) { $discount = max (0, min ($remainingValue, $voucher)); $discounts[$order][$id] = $discount; $remainingValue -= $discount; } $discounts[$order]['rest plata'] = $remainingValue; } var_dump($discounts);
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { [50]=> array(4) { [1]=> int(50) [3]=> int(0) [5]=> int(0) ["rest plata"]=> int(0) } [100]=> array(4) { [1]=> int(100) [3]=> int(0) [5]=> int(0) ["rest plata"]=> int(0) } [200]=> array(4) { [1]=> int(100) [3]=> int(100) [5]=> int(0) ["rest plata"]=> int(0) } [300]=> array(4) { [1]=> int(100) [3]=> int(150) [5]=> int(50) ["rest plata"]=> int(0) } [500]=> array(4) { [1]=> int(100) [3]=> int(150) [5]=> int(100) ["rest plata"]=> int(150) } [1000]=> array(4) { [1]=> int(100) [3]=> int(150) [5]=> int(100) ["rest plata"]=> int(650) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
46.46 ms | 402 KiB | 8 Q