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) { $vouchers2 = $vouchers; foreach ($vouchers2 as $voucher) { $discounts[$order][$voucher] = 0; } $remainingValue = $order; $voucher = array_pop($vouchers2); if ($voucher === null) { continue; } while($remainingValue >= 0 && $voucher !== null) { $value = min ($remainingValue, $voucher); $discounts[$order][$voucher] = $value; $voucher = array_pop($vouchers2); $remainingValue -= $value; } } var_dump($discounts);
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { [50]=> array(2) { [100]=> int(0) [150]=> int(0) } [100]=> array(2) { [100]=> int(0) [150]=> int(0) } [200]=> array(2) { [100]=> int(0) [150]=> int(100) } [300]=> array(2) { [100]=> int(50) [150]=> int(150) } [500]=> array(2) { [100]=> int(100) [150]=> int(150) } [1000]=> array(2) { [100]=> int(100) [150]=> int(150) } }

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:
51.83 ms | 402 KiB | 8 Q