Combinations of all sub array elements without repeats

前端 未结 2 612
悲&欢浪女
悲&欢浪女 2021-01-16 03:14

I have \"attributes\" from database. Each attribute has many values. Now I want to mix these values to create unique combinations.

example of input:

         


        
2条回答
  •  野的像风
    2021-01-16 03:22

    you can use this: https://gist.github.com/jwage/11193216

    or

    use the code bellow:

     $rightItem) {
                $results[] = array_merge((array) $leftItem, (array) $rightItem);
            }
        }
        return $results;
    }
    
    $y = $attributes[0];
    
    foreach($attributes as $key => $attrs) {
        if(isset($attributes[$key + 1]) && is_array($attributes[$key + 1])) {
            $y = array_mix($y, $attributes[$key + 1]);
        }
    }
    
    var_dump($y);
    

提交回复
热议问题