There is an array $test = ['a','b','c','d'];
As a result, it is necessary to obtain possible combinations of the given array, without pavtora (a, b | b, a) in the necessary order;
a b c d a,b a,c a,d b,c b,d c,d a,b,c a,b,d ....
I can not figure out how to implement it. I tried this way.
$test = ['a','b','c','d']; $new = []; foreach ($test as $value) { $new[] = $value; foreach ($test as $value1) { if($value != $value1) { // $new[] = $value; $new[] = $value.','.$value1; } } } function sort_value_strlen($a, $b) { return mb_strlen($a) - mb_strlen($b); } uasort($new, 'sort_value_strlen'); print_r($new);
But it does not work as I need. Result
Array ( [0] => a [4] => b [8] => c [12] => d [1] => a,b [2] => a,c [3] => a,d [5] => b,a [6] => b,c [7] => b,d [9] => c,a [10] => c,b [11] => c,d [13] => d,a [14] => d,b [15] => d,c )
It does not go more than 2 values + there are repetitions (a, b | b, a)
And is it possible to implement without using functions?