Generate PHP combinations for size and color
I am trying to figure out how to generate combinations of sizes with colors in php. Basically here is what I have:
- Sizes: Small, Medium, Large
- Size Count: 3
- Colors: Blue, Red, White
- C开发者_运维问答olor Count: 3
The sizes and colors may vary depending on each product. The outcome I would like to have is like this:
Small Blue
Small Red Small White Medium Blue Medium Red Medium White Large Blue Large Red Large White
$sizes = array('Small', 'Medium', 'Large');
$colors = array('Blue', 'Red', 'White');
foreach($sizes as $size) {
foreach($colors as $color) {
echo $size." ".$color;
}
}
That will give the output you described.
精彩评论