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-没问题。只要确定它是否回答了你的问题。