<?php
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('1', '2', '3','4');
  pc_permute($arr);
  ?>
Çıktı
Alıntı
1 2 3 4
2 1 3 4
1 3 2 4
3 1 2 4
2 3 1 4
3 2 1 4
1 2 4 3
2 1 4 3
1 4 2 3
4 1 2 3
2 4 1 3
4 2 1 3
1 3 4 2
3 1 4 2
1 4 3 2
4 1 3 2
3 4 1 2
4 3 1 2
2 3 4 1
3 2 4 1
2 4 3 1
4 2 3 1
3 4 2 1
4 3 2 1
Bunun gibi mi ?