[wd_asp elements=’search’ ratio=’100%’ id=1]

Permutations – Random

29th July 2016

Php - Miscellaneous

php codehaven


function pc_permute($items, $perms = array()) {
if (empty($items)) {
echo join(' ', $perms) . "
";
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $newperms);
}
}
}

$arr = array('Code', 'Haven', 'Website');

pc_permute($arr);