Skip to content

Instantly share code, notes, and snippets.

@luanlmd
Created March 8, 2010 18:24
Show Gist options
  • Save luanlmd/325423 to your computer and use it in GitHub Desktop.
Save luanlmd/325423 to your computer and use it in GitHub Desktop.
<?php
class ArrayMixer
{
function __construct($options)
{
$this->options = $options;
$this->result = array();
}
function go($arr, $x)
{
$x++;
if (count($this->options) == $x) { $this->result[] = $arr; return; }
foreach($this->options[$x] as $i)
{
$arr2 = $arr;
$arr2[] = $i;
$this->go($arr2, $x);
}
}
function mix()
{
$this->go(array(),-1);
return $this->result;
}
}
$options = array(
array('a','b','c'),
array('1','2'),
array('X','Y')
);
$a = new ArrayMixer($options);
var_dump($a->mix());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment