lithium\test\Unit::_arrayPermute()
Generates all permutation of an array $items and returns them in a new array.
Parameters
-
array
$items
An array of items
-
array
$perms
Returns
arraySource
protected function _arrayPermute($items, $perms = []) {
static $permuted;
if (empty($perms)) {
$permuted = [];
}
if (empty($items)) {
$permuted[] = $perms;
return;
}
$numItems = count($items) - 1;
for ($i = $numItems; $i >= 0; --$i) {
$newItems = $items;
$newPerms = $perms;
list($tmp) = array_splice($newItems, $i, 1);
array_unshift($newPerms, $tmp);
$this->_arrayPermute($newItems, $newPerms);
}
return $permuted;
}