3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weight_distribution = [ '1' => 0, '2-5' => 0, '5-10' => 6, '10-15' => 7, '15-20' => 3, ]; function distribute_weights(int|float $weight, array &$distribution): void { $parsed = []; foreach ($distribution as $range => $cost) { if (sscanf($range, '%d-%d', $min, $max) === 1) { $default = [$min, $min]; } else { $parsed[] = [$min, $max]; } } while ($weight > 0) { foreach ($parsed as $i => [$min, $max]) { if ($weight <= $max) { if (!$i && $weight <= $min) { [$min, $max] = $default; } break; } } if ($min === $max) { ++$distribution[$max]; } else { ++$distribution[$min . '-' . $max]; } $weight -= $max; } } distribute_weights(21, $weight_distribution); print_r($weight_distribution);
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [1] => 1 [2-5] => 0 [5-10] => 6 [10-15] => 7 [15-20] => 4 )

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:
79.99 ms | 405 KiB | 5 Q