Created
May 28, 2014 04:57
-
-
Save blpraveen/1091c6d04070cafb0e20 to your computer and use it in GitHub Desktop.
Generate Combinations from sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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