$skuattr = Array ( '7' => Array ( '6' => '22x33', '9' => '44x55', ), '8' => Array ( '12' => '大小号' ), '9' => Array ( '8' => '金属质', '13' => '塑料', ), '16' => Array ( '14' => '圆形' ) );
Get 4 values
7:6;8:12;9:8;16:14;
7:9;8:12;9:8;16:14
7:6;8:12;9:13;16:14
7:9;8:12;9:13;16:14
Because the key value is dynamic, it takes an array traversal algorithm to get the result, the great God Help
Reply content:
$skuattr = Array ( '7' => Array ( '6' => '22x33', '9' => '44x55', ), '8' => Array ( '12' => '大小号' ), '9' => Array ( '8' => '金属质', '13' => '塑料', ), '16' => Array ( '14' => '圆形' ) );
Get 4 values
7:6;8:12;9:8;16:14;
7:9;8:12;9:8;16:14
7:6;8:12;9:13;16:14
7:9;8:12;9:13;16:14
Because the key value is dynamic, it takes an array traversal algorithm to get the result, the great God Help
The principle is to ask the Cartesian product to write a simple example
php
function Combinedika ($data) {$result = array (); foreach (Array_shift ($data) as $k = + $item) {$result [] = Array ($k + = $item); } foreach ($data as $k = + $v) {$result 2 = []; foreach ($result as $k 1=> $item 1) {foreach ($v as $k 2=> $item 2) {$temp = $item 1; $temp [$k 2] = $item 2; $result 2[] = $temp; }} $result = $result 2; } return $result;} $skuattr = Array (' 7 ' = = Array (' 6 ' = ' = ' 22x33 ', ' 9 ' = ' 44x55 ',), ' 8 ' = = array (' + ' = ' size '), ' 9 ' = = Array (' 8 ' = ' metal ', ' ' + ' = ' plastic '), ' 16 ' = = Array (' + ' = ' round '); $a = Combinedika ($skuattr);p rint_r ($a);
php
Array( [0] => Array ( [6] => 22x33 [12] => 大小号 [8] => 金属质 [14] => 圆形 ) [1] => Array ( [6] => 22x33 [12] => 大小号 [13] => 塑料 [14] => 圆形 ) [2] => Array ( [9] => 44x55 [12] => 大小号 [8] => 金属质 [14] => 圆形 ) [3] => Array ( [9] => 44x55 [12] => 大小号 [13] => 塑料 [14] => 圆形 ))