0

我必须通过独特的价值和有序的方式生成元素的所有组合。我用一个例子来解释,这些是参数和它们的值:

Dog : mal | female
Color : red | blue | yellow

the all combinations (ordered) to get are :
male - red
male - blue
male - yellow
female - red
female - blue
female - yellow

我如何使用数组在 php 中做到这一点?

提前致谢

4

1 回答 1

2
$dogs = array( 'male', 'female');
$colors = array( 'red', 'blue', 'yellow');

foreach( $dogs as $dog)
    foreach( $colors as $color)
        echo $dog . ' - ' . $color . "\n";

输出:

male - red
male - blue
male - yellow
female - red
female - blue
female - yellow

演示

于 2012-06-07T01:51:50.777 回答