When the locomotive launches the product, it has the color, size, gender and so on product attributes, need to do not duplicate the combination, becomes the non-repeating array
<?PHPfunctionComb ($a){ $a=Array_filter($a); $out=Array(); if(Count($a) = = 1) { $r=Array_shift($a); foreach($r as $v)$out[] =Array($v); return $out; } foreach($a as $k=$v){ $b=$a; unset($b[$k]); $r= Comb ($b); foreach($v as $v 1){ foreach($r as $v 2) $out[] =Array_merge(Array($v 1),$v 2); } Break; } return $out;}$array 1=Array(Array(' Red ', ' Black ', ' Yellow '),Array(' Boy ', ' Girl '),Array(' S ', ' M ', ' L '));$result= Comb ($array 1);
Print_r($result);
?>
The results returned are as follows:
Array( [0] = =Array ( [0] = =Red [1] = =Boy [2] = =S) [1] = =Array ( [0] = =Red [1] = =Boy [2] = =M) [2] = =Array ( [0] = =Red [1] = =Boy [2] = =L) [3] = =Array ( [0] = =Red [1] = =Girl [2] = =S) [4] = =Array ( [0] = =Red [1] = =Girl [2] = =M) [5] = =Array ( [0] = =Red [1] = =Girl [2] = =L) [6] = =Array ( [0] = =Black [1] = =Boy [2] = =S) [7] = =Array ( [0] = =Black [1] = =Boy [2] = =M) [8] = =Array ( [0] = =Black [1] = =Boy [2] = =L) [9] = =Array ( [0] = =Black [1] = =Girl [2] = =S) [+] =Array ( [0] = =Black [1] = =Girl [2] = =M) [[One] =Array ( [0] = =Black [1] = =Girl [2] = =L) [+] =Array ( [0] = =Yellow [1] = =Boy [2] = =S) [+] =Array ( [0] = =Yellow [1] = =Boy [2] = =M) [+] =Array ( [0] = =Yellow [1] = =Boy [2] = =L) [[] =Array ( [0] = =Yellow [1] = =Girl [2] = =S) [+] =Array ( [0] = =Yellow [1] = =Girl [2] = =M) [+] =Array ( [0] = =Yellow [1] = =Girl [2] = =L))
PHP multiple array combination algorithm locomotive free login Publish interface Code memo