3v4l.org

run code in 300+ PHP versions simultaneously
<?php function change_top_items($array, $top_x) { uasort($array, function($a, $b) { if ($a == $b) return 0; return ($a < $b) ? -1 : 1; }); $compare = array_slice($array, -$top_x); $modified = array_map(function($value) use ($compare) { return in_array($value, $compare) ? 1 : 0; }, $array); ksort($modified); return $modified; } $a = [5, 8, 2, 0, 1, 9, 1, 0, 5, 4]; print_r(change_top_items($a, 5));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 1 [1] => 1 [2] => 0 [3] => 0 [4] => 0 [5] => 1 [6] => 0 [7] => 0 [8] => 1 [9] => 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:
40.62 ms | 401 KiB | 8 Q