Permuted numbers using php

Hello

suppose I have 6 numbers in a variable $numbers, for example

$numbers=“12.24.34.45.56”;

and I have to add in $comb array all the combinations using 5 numbers (number in the variable - 1) to have this

12.24.34.45
12.24.34.56

24.34.45.56

someone can tell me how I can do it with php

Thank You

I found solution on stackoverflow.com unluckly the forum does not permit me to share the url

so all combinations permutations of the elements of an array.

Basic Recursion Algorithm.

function make_a_snake($in) {
 $output = array();
 if(count($in) == 1 ) return $in; //Short Circuit - End of Recursion Depth.
 foreach($in AS $out) {
    $result = make_a_snake(array_diff($in,array($out)));
    foreach($result AS $suffix) {
        $output[] = $out.".".$suffix;
	}
  }
  return $output;
}

EDIT: Bad StarLion. Bad mixing up the maths terms. Bad. Go to your coding corner and think about what you’ve done.

i agree with you for this code . :grin:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.