Lagbolt,
Here's the answer in PHP:
$words = array(1,2,3,4);
$num = count($words);
//The total number of possible combinations
$total = pow(2, $num);
//Loop through each possible combination
for ($i = 0; $i < $total; $i++) {
//For each combination check if each bit is set
for ($j = 0...