Combination - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Combination.php

  1. <?php
  2. class Combination{
  3.  
  4. public static $n=1;
  5.   static function combinations2(array $arr,  $len,  $startPosition, array $result):void{
  6.         if ($len == 0){
  7.             
  8.             print(self::$n." : ".$result[0].$result[1].$result[2]);
  9.             echo("\n");
  10.             self::$n++;
  11.             return;
  12.         }       
  13.         for ( $i = $startPosition; $i <= (count($arr)-$len); $i++){
  14.             $result[count($result) - $len] = $arr[$i];
  15.             
  16.            // print_r($result);
  17.             Combination::combinations2($arr, $len-1, $i+1, $result);
  18.         }
  19.         
  20.     }  
  21.    
  22. }
  23.  
  24. $arr = ["1","2","3","4","5","6"];
  25. $tab = ["","",""];
  26. //print_r($arr);
  27.  
  28. $comb=new Combination();
  29. $comb->combinations2( $arr, 3, 0, $tab );
File Description
  • Combination
  • PHP Code
  • 20 Apr-2022
  • 733 Bytes
You can Share it: