Skip to content

Instantly share code, notes, and snippets.

@blpraveen
Created May 28, 2014 04:57
Show Gist options
  • Save blpraveen/1091c6d04070cafb0e20 to your computer and use it in GitHub Desktop.
Save blpraveen/1091c6d04070cafb0e20 to your computer and use it in GitHub Desktop.
Generate Combinations from sets
function get_combination($array_sets) {
$count = count($array_sets);
if(is_array($array_sets[0]) && $count > 1) {
$first_set = $array_sets[0];
if($count > 2) {
$oth_room_set = get_combinations(array_slice($array_sets, 1));
} else {
$oth_room_set = $array_sets[1];
}
$array_comb = array();
foreach($first_set as $araele1) {
foreach($oth_room_set as $araele2) {
if(is_array($araele2)) {
$array_comb[] = array_merge(array($araele1),$araele2);
} else {
$array_comb[] = array($araele1,$araele2);
}
}
}
return $array_comb;
} else {
return $array_sets;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment