0

I want to get all the possible combination from an array. I know this question has been asked several times but didnot worked for me correctly .

The array input should be single dimensional array as well as the output

for example:- input

$new_array=array('c','a','t','m','p');

possible combinations such as ca,ct,cm,cp,cat,cam,cap.... and soo on...

I have tried this but didnot worked correctly .

I have taken the code from PHP CookBook

function pc_array_power_set($array) {
    // initialize by adding the empty set
    $results = array();

    foreach ($array as $element)
        foreach ($results as $combination)
            array_push($results, array_merge($eleme, $combination));

    return $results;
}

$set = array('c', 'a', 't','m','p');
$power_set = pc_array_power_set($set);

print_r($power_set);

I need the output in single dimensional array

mod geek
  • 310
  • 2
  • 18

0 Answers0