<?php

error_reporting(-1);

$elements = [1, 2, 3];

function factorial($n){
	if($n <= 1){
		return 1;
	} else {
		return $n * factorial($n - 1);
	}
}

function getCombinations($elements){
	//print_r($elements);
	if(count($elements) == 1){
		return [$elements];
	}
	$result = [];
	foreach($elements as $key => $element){
		$first = $element;
		$firstKey = $key;
		unset($elements[$key]);
		$combinations = getCombinations($elements);
		$elements[] = $first;
		print_r($elements);
		foreach($combinations as &$combination){
			array_unshift($combination, $first);
			$result[] = $combination;
		}

	}
	return $result;
}

$result = getCombinations($elements);
//print_r($result);