Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 生成所有元素的组合_Php_Arrays_Attributes_Combinations - Fatal编程技术网

Php 生成所有元素的组合

Php 生成所有元素的组合,php,arrays,attributes,combinations,Php,Arrays,Attributes,Combinations,我必须以独特的价值和有序的方式生成所有元素的组合。 我用一个例子解释,这些是参数及其值: 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中实现它 提前谢谢 $dogs = arr

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

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中实现它

提前谢谢

$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

我同意这是一个糟糕的问题,但如果你否决了一位新成员,请留下一些解释。Jojo,建议你看看常见问题,我想我从来没有见过一只蓝色的狗…为什么我要找更复杂的。。。?非常感谢您的快速回复nickb@JojoLapin45-没问题。只要确定它是否回答了你的问题。