3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Returns the total number of $count-length strings generatable from $letters. function getPermCount($letters, $count) { $result = 1; // k characters from a set of n has n!/(n-k)! possible combinations for($i = strlen($letters) - $count + 1; $i <= strlen($letters); $i++) { $result *= $i; } return $result; } // Decodes $index to a $count-length string from $letters, no repeat chars. function getPerm($letters, $count, $index) { $result = array(); for($i = 0; $i < $count; $i++) { $pos = $index % strlen($letters); $result[] = $letters[$pos]; $index = ($index-$pos)/strlen($letters); $letters = substr($letters, 0, $pos) . substr($letters, $pos+1); } sort($result); return implode("", $result); } $r = array(); //$letters = 'abcdefghijklm'; $letters = 'abcdef'; $len = strlen($letters); for ($c = 1; $c <= $len; $c++) for($i = 0; $i < getPermCount($letters, $c); $i++) $r[] = getPerm($letters, $c, $i); print_r(array_unique($r, SORT_REGULAR));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => ab [8] => ac [9] => ad [10] => ae [11] => af [13] => bc [15] => bd [16] => be [17] => bf [20] => cd [22] => ce [23] => cf [27] => de [29] => df [34] => ef [36] => abc [39] => abd [40] => abe [41] => abf [50] => acd [52] => ace [53] => acf [57] => ade [59] => adf [64] => aef [73] => bcd [76] => bce [77] => bcf [87] => bde [89] => bdf [94] => bef [110] => cde [113] => cdf [124] => cef [147] => def [156] => abcd [160] => abce [161] => abcf [177] => abde [179] => abdf [184] => abef [230] => acde [233] => acdf [244] => acef [267] => adef [313] => bcde [317] => bcdf [334] => bcef [387] => bdef [470] => cdef [516] => abcde [521] => abcdf [544] => abcef [627] => abdef [830] => acdef [1033] => bcdef [1236] => abcdef )

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:
41.95 ms | 403 KiB | 8 Q