Permuted numbers using php


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


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

someone can tell me how I can do it with php

Thank You

I found solution on 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.