3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 2 => 5, 4 => 1, 8 => 3, 0 => 17, 9 => 2, 11 => 67 ]; $ranges = [ '1-5' => ['min' => 1, 'max' => 5], '6-10' => ['min' => 6, 'max' => 10], '1000-5000' => ['min' => 1000, 'max' => 5000], ]; $result = []; foreach ($ranges as $rangeName => ['min' => $min, 'max' => $max]) { $result[$rangeName] = 0; foreach ($array as $num => $amount) { if ($num < $min) { unset($array[$num]); } elseif ($num <= $max) { $result[$rangeName] += $amount; unset($array[$num]); } } } var_export($result);
Output for git.master, git.master_jit
array ( '1-5' => 6, '6-10' => 5, '1000-5000' => 0, )

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:
55.76 ms | 862 KiB | 4 Q