Sorry for the title, as it is similar to most other questions about array joining, but I don't know how to write it more specifically.
I need a PHP function that combines the entries of one array (dynamic size from 1 to any) to strings in any possible combination.
Here is an example with 4 entries:
$input = array('e1','e2','e3','e4);
This should be the result of:
$result = array(
0 => 'e1',
1 => 'e1-e2',
2 => 'e1-e2-e3',
3 => 'e1-e2-e3-e4',
4 => 'e1-e2-e4',
5 => 'e1-e3',
6 => 'e1-e3-e4',
7 => 'e1-e4'
8 => 'e2',
9 => 'e2-e3',
10 => 'e2-e3-e4',
11 => 'e2-e4',
12 => 'e3',
13 => 'e3-e4',
14 => 'e4'
);
Sorting the input array is relevant as it affects the output. And as you can see, there should be a result like e1-e2, but not e2-e1.
This seems very complicated since the input array can have any number of entries. I donβt even know if there is a mathematical construction or a name that describes such a case.
Has anyone done this before?