Created
December 13, 2019 13:15
-
-
Save fraszczakszymon/1150b4585cb92b445aacee55449da101 to your computer and use it in GitHub Desktop.
String combinations generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = [ | |
[ 'hb_' ], | |
[ 'bidder_', 'pb_', 'adid_', 'size_' ], | |
[ | |
'33across', | |
'aol', | |
'appnexus', | |
'appnexusAst', | |
'beachfront', | |
'criteo', | |
'gumgum', | |
'indexExchange', | |
'kargo', | |
'lkqd', | |
'onemobile', | |
'openx', | |
'pubmatic', | |
'rubicon', | |
'rubicon_display', | |
'teads', | |
'triplelift', | |
'vmg', | |
'wikia', | |
'wikiaVideo', | |
], | |
]; | |
function generateCombinations($arrays, $i = 0) | |
{ | |
if (!isset($arrays[$i])) { | |
return array(); | |
} | |
if ($i == count($arrays) - 1) { | |
return $arrays[$i]; | |
} | |
$tmp = generateCombinations($arrays, $i + 1); | |
$result = array(); | |
foreach ($arrays[$i] as $v) { | |
foreach ($tmp as $t) { | |
$result[] = implode('', [$v, $t]); | |
} | |
} | |
return $result; | |
} | |
foreach (generateCombinations($input) as $row) { | |
print($row . "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment