Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getCombinations($base,$n){
- $baselen = count($base);
- if($baselen == 0){
- return;
- }
- if($n == 1){
- $return = array();
- foreach($base as $b){
- $return[] = array($b);
- }
- return $return;
- }else{
- $oneLevelLower = getCombinations($base,$n-1);
- $newCombs = array();
- foreach($oneLevelLower as $oll){
- $lastEl = $oll[$n-2];
- $found = false;
- foreach($base as $key => $b){
- if($b == $lastEl){
- $found = true;
- continue;
- }
- if($found == true){
- if($key < $baselen){
- $tmp = $oll;
- $newCombination = array_slice($tmp,0);
- $newCombination[]=$b;
- $newCombs[] = array_slice($newCombination,0);
- }
- }
- }
- }
- }
- return $newCombs;
- }
- $set=array(1, 2, 3, 4);
- $count = count($set);
- $result = array();
- for($i = 1; $i <= $count; $i++){
- $result[] = getCombinations($set, $i);
- }
- echo "<pre>";
- print_r($result);
- echo "</pre>";
- $res = count($result);
- for($i=0;$i<$res;$i++){
- for($f=0;$f<$res;$f++){
- for($g=0;$g<$res;$g++){
- echo $result[$i][$f][$g];
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment