You can achieve this easily with foreach loops:
$array1 = array('100GB', '500GB');
$array2 = array('black', 'yellow', 'green');
$array3 = array('2.5');
$combinations = array();
foreach ($array1 as $i) {
foreach ($array2 as $j) {
foreach ($array3 as $k) {
$combinations[] = $i.' - '.$j.' - '.$k;
}
}
}
echo implode("\n", $combinations);
Edit: To handle empty arrays, you could use this function:
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;
}
This function was taken from this answer, so credit goes to the author. You can then call this combinations
function this way:
$array1 = array('100GB', '500GB');
$array2 = array();
$array3 = array('2.5');
$arrays = array_values(array_filter(array($array1, $array2, $array3)));
$combinations = combinations($arrays);
foreach ($combinations as &$combination) {
$combination = implode(' - ', $combination);
}
echo implode("\n", $combinations);
This outputs:
100GB - 2.5
500GB - 2.5