Let me explain, i need this to develop a unique title generator based on a set of words pre defined.
For example, i have this list of words:
$list = ['apple', 'banana', 'pear'];
I have a limited size of the title, for example: 1 characters If i generate a list of all permutation, i will have:
apple
banana
pear
apple banana
apple pear
apple banana pear
banana apple
banana pear
banana apple pear
pear apple
pear banana
pear banana apple
But i don't want this, ny rules are: Words cannot repeat again in another set of words and i want only the biggest set of words <= 12 characteres
The result would be:
apple banana
apple pear
banana pear
I already tried following solutions but none of these help:
PHP algorithm to generate all combinations of a specific size from a single set
Every (specific sized) combination from set/array with no duplicate items
Efficient PHP algorithm to generate all combinations / permutations of inputs
How do you generate a list of all possible strings given a generator of characters and a length?
I have this code, but it is not removing duplicates as i want
public static function search_get_combos($array = array(), $maxCaracters=12) {
        sort($array);
        $terms = array();
        for ($dec = 1; $dec < pow(2, count($array)); $dec++) {
            $curterm = array();
            foreach (str_split(strrev(decbin($dec))) as $i => $bit) {
                if ($bit) {
                    $curterm[] = $array[$i];
                }
            }
            if (!in_array($curterm, $terms) && count($curterm) > 1) {
                $title = implode(' ', $curterm);
                if (strlen($title) <= $maxCaracters){
                    $terms[$title] = $curterm;
                }
            }
        }
        return $terms;
    }
Output:
array(6) {
  ["Apple"]=>
  array(1) {
    [0]=>
    string(5) "Apple"
  }
  ["Banana"]=>
  array(1) {
    [0]=>
    string(6) "Banana"
  }
  ["Apple Banana"]=>
  array(2) {
    [0]=>
    string(5) "Apple"
    [1]=>
    string(6) "Banana"
  }
  ["Pear"]=>
  array(1) {
    [0]=>
    string(4) "Pear"
  }
  ["Apple Pear"]=>
  array(2) {
    [0]=>
    string(5) "Apple"
    [1]=>
    string(4) "Pear"
  }
  ["Banana Pear"]=>
  array(2) {
    [0]=>
    string(6) "Banana"
    [1]=>
    string(4) "Pear"
  }
}
 
    