PHP可能有限的数组组合[关闭]

Here i have used following function to get the possible combinations for the given array.

    function combination($array, $str = '') 
{
   $current = array_shift($array);
   if(count($array) > 0) {
       foreach($current as $element) 
       {

           combination($array, $str.$element);

       }
   }
   else
   {
       foreach($current as $element) 
       {
         echo '<br>'.$str.$element;

       }
   } 
}

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



combination($array);    

    OUTPUT:
A1 B1 C1
A1 B1 C2
A1 B2 C1
A1 B2 C2
A1 B3 C1
A1 B3 C2
A1 B4 C1
A1 B4 C2
A2 B1 C1
A2 B1 C2
A2 B2 C1
A2 B2 C2
A2 B3 C1
A2 B3 C2
A2 B4 C1
A2 B4 C2
A3 B1 C1
A3 B1 C2
A3 B2 C1


EXPECTED: In this i want only to display first 10 combinations.

Here i am getting the all possible combinations of given array. But i want to display only the first 10 combinations of possible array. Please help me to overcome the issue.

查看全部
dongshou2024
dongshou2024
2015/05/28 09:33
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复