So, I have been trying to adapt all the examples I have found but haven’t quite found the solution.
What I would like to end up with is a list off all the permutations of a combination of letters and numbers but the output is always has 2 letters and 2 numbers (in all orders).
What I have so far is:
function combinations($arrays, $i = 0) {
if (!isset($arrays[$i])) {
return array();
}
if ($i == count($arrays) - 1) {
return $arrays[$i];
}
// get combinations from subsequent arrays
$tmp = combinations($arrays, $i + 1);
$result = array();
// concat each array from tmp with each element from $arrays[$i]
foreach ($arrays[$i] as $v) {
foreach ($tmp as $t) {
$result[] = is_array($t) ?
array_merge(array($v), $t) :
array($v, $t);
}
}
return $result;
}
$letters = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$numbers = array("0","1","2","3","4","5","6","7","8","9");
$combinations = combinations(array( $letters, $letters, $numbers, $numbers));
foreach ($combinations as $values) {
echo implode("",$values).'<br>';
}
But that only outputs results in the order of 2 letters first followed by the two numbers.
Also bonus question, how do I calculate the total results I should be expecting, I know if it was all letters, it would be 26x26x26x26 so 4 letters only I would be expecting 456,976, but what about 2 letters & 2 numbers?