3v4l.org

run code in 300+ PHP versions simultaneously
<?php function permuteUnique($items, $perms = [], &$return = []) { if (empty($items)) { $return[] = $perms; } else { sort($items); $prev = false; for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $tmp = array_splice($newitems, $i, 1)[0]; if ($tmp != $prev) { $prev = $tmp; $newperms = $perms; array_unshift($newperms, $tmp); permuteUnique($newitems, $newperms, $return); } } return $return; } } $permutations = permuteUnique(["x1", "x2", "x3"]); var_dump($permutations);
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { [0]=> array(3) { [0]=> string(2) "x1" [1]=> string(2) "x2" [2]=> string(2) "x3" } [1]=> array(3) { [0]=> string(2) "x2" [1]=> string(2) "x1" [2]=> string(2) "x3" } [2]=> array(3) { [0]=> string(2) "x1" [1]=> string(2) "x3" [2]=> string(2) "x2" } [3]=> array(3) { [0]=> string(2) "x3" [1]=> string(2) "x1" [2]=> string(2) "x2" } [4]=> array(3) { [0]=> string(2) "x2" [1]=> string(2) "x3" [2]=> string(2) "x1" } [5]=> array(3) { [0]=> string(2) "x3" [1]=> string(2) "x2" [2]=> string(2) "x1" } }

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.95 ms | 402 KiB | 8 Q