- array_splice: documentation ( source)
- array_unshift: documentation ( source)
- range: documentation ( source)
<?php
$items = range('a', 'g');
function permute($items, $perms = array( )) {
if (empty($items)) {
return($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);
permute($newitems, $newperms);
}
}
}
permute($items);