3v4l.org

run code in 300+ PHP versions simultaneously
<?php function permutations($set) { $solutions=array(); $n=count($set); $p=array_keys($set); $i=1; while ($i<$n) { if ($p[$i]>0) { $p[$i]--; $j=0; if ($i%2==1) $j=$p[$i]; //swap $tmp=$set[$j]; $set[$j]=$set[$i]; $set[$i]=$tmp; $i=1; $solutions[]=$set; } elseif ($p[$i]==0) { $p[$i]=$i; $i++; } } return $solutions; } $set=array("x1", "x2", "x3"); print_r(permutations($set));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [0] => x2 [1] => x1 [2] => x3 ) [1] => Array ( [0] => x3 [1] => x1 [2] => x2 ) [2] => Array ( [0] => x1 [1] => x3 [2] => x2 ) [3] => Array ( [0] => x2 [1] => x3 [2] => x1 ) [4] => Array ( [0] => x3 [1] => x2 [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:
46.96 ms | 402 KiB | 8 Q