function combineArray (&$arr, $idx = 0) {
static $line = array();
static $keys;
static $max;
static $results;
if ($idx == 0) {
$keys = array_keys($arr);
$max = count($arr);
$results = array();
}
if ($idx < $max) {
$values = $arr[$keys[$idx]];
foreach ($values as $value) {
array_push($line, $value);
combineArray($arr, $idx+1);
array_pop($line);
}
} else {
$results[] = $line;
}
if ($idx == 0) return $results;
}