3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "Jacob" => 5, "bob" => 20, "John" => 10, "Jane" => 20, "Jill" => 15, ]; $limit = 3; $result = []; foreach ($array as $k => $v) { if (isset($result[$v])) { $result[$v][$k] = $v; } elseif (count($result) < $limit) { $result[$v][$k] = $v; } else { $min = min(array_keys($result)); if ($v > $min) { $result[$v][$k] = $v; unset($result[$min]); } } } krsort($result); var_export(array_values($result));
Output for git.master, git.master_jit
array ( 0 => array ( 'bob' => 20, 'Jane' => 20, ), 1 => array ( 'Jill' => 15, ), 2 => array ( 'John' => 10, ), )

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:
54.1 ms | 999 KiB | 4 Q