- array_splice: documentation ( source)
- array_unshift: documentation ( source)
- str_split: documentation ( source)
- join: documentation ( source)
<?php
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);
}
}
}
$chars = "01234567890";
$arr = str_split($chars);
#$arr = array('peter', 'paul', 'mary');
pc_permute($arr);
?>