Skip to content

Instantly share code, notes, and snippets.

@fraszczakszymon
Created December 13, 2019 13:15
Show Gist options
  • Save fraszczakszymon/1150b4585cb92b445aacee55449da101 to your computer and use it in GitHub Desktop.
Save fraszczakszymon/1150b4585cb92b445aacee55449da101 to your computer and use it in GitHub Desktop.
String combinations generator
<?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