@Parag Tyagi: Thanks a lot!!
I modified a little your code and made it a function:
function get_arrays_combinations($array1, $array2) {
$num = count($array2);
$comb = array();
// The total number of possible combinations.
$total = pow(2, $num);
// Loop through each possible combination.
for ($i = 0; $i < $total; $i++) {
$flag = '';
for ($j = 0; $j < $num; $j++) { // For each combination check if each bit is set.
if (pow(2, $j) & $i) { // Is bit $j set in $i?
if (empty($flag)) {
$flag = $array2[$j];
}
else {
$flag = $flag . "-" . $array2[$j];
}
}
}
if(!empty($flag)) {
$comb[] = $flag;
}
}
// Now $comb has all the possible combinations of $array2.
// Just loop it through the other array and concat.
$result = array();
foreach($array1 as $val) {
foreach($comb as $co) {
$result[] = $val . "-" . $co;
}
}
return $result;
}
$array1 = array('A', 'B');
$array2 = array('1', '2', '3');
$combos = get_arrays_combinations($array1, $array2);
$combos outputs:
Array
(
[0] => A-1
[1] => A-2
[2] => A-1-2
[3] => A-3
[4] => A-1-3
[5] => A-2-3
[6] => A-1-2-3
[7] => B-1
[8] => B-2
[9] => B-1-2
[10] => B-3
[11] => B-1-3
[12] => B-2-3
[13] => B-1-2-3
)
Thank you very much, also to other users.
This is my first question (not visit) in StackOverflow and has been a wonderful experience :)