[Solved] PHP possible limited combinations of array [closed]


This is the best and optimal solution for you. try it:-

<?php
global $i;
$i = 1; // define a global variable with value 1
function combination($array, $str="") 
{
  global $i;
  $current = array_shift($array);
   if(count($array) > 0 && $i <=10) { // check that value is less or equal to 10 if yes then execute otherwise exit

       foreach($current as $element) 
       { 
           combination($array, $str.$element);
       }
   }
   if(count($array) <= 0 && $i <=10){ //again check if value is less or equal to 10 then execute otherwise exit 

       foreach($current as $element) 
       {        
            echo '<br>'.$str.$element;
            $i++; // increase the  value of global variable while iteration.
       }

   }
}


$array = array(array(' A1', ' A2', ' A3', ' A4'),array(' B1', ' B2', ' B3', ' B4'),array(' C1',' C2'));
combination($array);
?>

Output:- http://prntscr.com/7abrrx

Note:- Please check and tell works or not?

solved PHP possible limited combinations of array [closed]