There is an array of previously unknown quantities [1,2,3 ....], how to get all the possible combinations? The result should be as follows: ['12', '13', '23']

ps maybe there are options without use, loading the brain and the machine, recursions?

  • all possible lengths = 2 without order, or what? the algorithms seem to be all fairly well known, have you really not been able to find a solution yourself? - teran pm
  • one
    How does this list of all possible combinations suddenly turn out to consist of only '12', '13', '23'? Describe normally, what list do you need to get? - AnT

1 answer 1

Can so

$array=[1,2,3,4,5]; foreach($array as $v1){ foreach($array as $v2){ $result[$v1.$v2]=true; } } echo implode(',',array_keys($result));