开发者

Generate PHP combinations for size and color

开发者 https://www.devze.com 2023-01-29 06:38 出处:网络
I am trying to figure out how to generate combinations of sizes with colors in php. Basically here is what I have:

I am trying to figure out how to generate combinations of sizes with colors in php. Basically here is what I have:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号