Нужно перебрать элементы массива со всеми возможными вариантами Допустим есть массив: PHP: $arr = array('a', 'b', 'c'); На выходе нужно получить нечто такое Код (Text): abc bac bca bac abc acb cab acb abc Количество элементов не ограначено
Первый запрос в гугле: https://habrahabr.ru/sandbox/58709/ https://php.ru/forum/threads/kombinatorika-reshaet.15502/
то что кинули не то. Нашел это. Походу подходит PHP: function permuteUnique($items, $perms = [], &$return = []) { if (empty($items)) { $return[] = $perms; } else { sort($items); $prev = false; for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $tmp = array_splice($newitems, $i, 1)[0]; if ($tmp != $prev) { $prev = $tmp; $newperms = $perms; array_unshift($newperms, $tmp); permuteUnique($newitems, $newperms, $return); } } return $return; } } $permutations = permuteUnique(array('a', 'b', 'c'));