3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitItems(array $limits, int $total): array { asort($limits); foreach ($limits as &$limit) { $limit = min($limit, $total); $total -= $limit; } ksort($limits); return $limits; } var_export(splitItems([14, 2], 10)); echo "\n---\n"; var_export(splitItems([6, 8, 2], 14)); echo "\n---\n"; var_export(splitItems([6, 4, 2], 14)); echo "\n---\n"; var_export(splitItems([7, 7, 1], 4)); echo "\n---\n"; var_export(splitItems([1, 1], 10)); echo "\n---\n"; var_export(splitItems([2,1,3],4));
Output for git.master_jit, git.master
array ( 0 => 8, 1 => 2, ) --- array ( 0 => 6, 1 => 6, 2 => 2, ) --- array ( 0 => 6, 1 => 4, 2 => 2, ) --- array ( 0 => 3, 1 => 0, 2 => 1, ) --- array ( 0 => 1, 1 => 1, ) --- array ( 0 => 2, 1 => 1, 2 => 1, )

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