1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function pc_permute($items, $perms = array()) { if (empty($items)) { echo join(' ', $perms) . "<br />"; } 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); |
