Generate permutations from a number in PHP

0

I currently have this script

$str = $_GET[numero];
function permute($str,$i,$n) { 
      if ($i == $n) { 
         echo $str.'<br>';
      } else { 
        for ($j = $i; $j < $n; $j++) { 
        swap($str,$i,$j); 
        permute($str, $i+1, $n); 
        swap($str,$i,$j); 
      }
}
}

function swap(&$str,$i,$j) { 
 $temp = $str[$i];
 $str[$i] = $str[$j]; 
 $str[$j] = $temp; 
 } 

 echo permute($str,0,strlen($str));

But this script generates all the combinations but they are repeated a few times. What I want is that the number that is already generated is not repeated.

Thank you very much for your help.

    
asked by Carlos Maldonado 09.11.2018 в 04:50
source

0 answers