<?php
function recombine($right, $left = array())
{
	echo implode(' ', $left).PHP_EOL; // trace
	while($value = array_shift($right)) // walk through $right like queue (mutable!)
		recombine($right, array_merge(array($value), $left)); // go deep but put value to left
};

recombine(array(1, 2, 3, 4));
