1

i have this array

$dataArray = array
        (
        array(1,11,111),
        array(2,22,222),
        array(3,33,333),
        array(4,44,444)
    );

I also Google for it but no useful PHP script found..

Result using permutation combination method

1,11,111
1,111,11
11,111
1,11,
2,11,111
2,11,1
.
.
.
.

and yes i have already tried it with permutation combination method

function permutations(array $array, $r=false)
    {
        switch (count($array)) {
            case 1:
                return $array[0];
                break;
        }

        $keys = array_keys($array);

        $a = array_shift($array);
        $k = array_shift($keys); // Get the key that $a had
        $b = permutations($array, 'recursing');

        $return = array();
        foreach ($a as $v) {
            if($v)
            {
                foreach ($b as $v2) {
                    if($r == 'recursing')
                        $return[] = array_merge(array($v), (array) $v2);
                    else
                        $return[] = array($k => $v) + array_combine($keys, $v2);
                }
            }
        }

    return $return;
}


$x = permutations($dataArray);      
echo "<pre>";               
print_r($x);
Naresh
  • 2,761
  • 10
  • 45
  • 78
  • what do you want to get at the end? – ahmetunal Mar 13 '13 at 10:24
  • Site search have thrown these for Permutations: http://stackoverflow.com/questions/13525893/array-permutation-in-php and for Combinations: http://stackoverflow.com/questions/3742506/php-array-combinations – complex857 Mar 13 '13 at 10:31
  • Try the Math_Combinatorics PEAR package: http://pear.php.net/package/Math_Combinatorics – alganet Mar 13 '13 at 10:40

0 Answers0