The result of "Array 3" is obtained according to "Array 1" and "Array 2", and it is better to be efficient.
Array 2 is a set of properties; Array 1 is a product that may fill only one or a few properties
Array 1Array ([100008]/= Array ([5] = = Array ([name] = Price Lattice [0] = = not limited to) [6] = = Array ([name] = > Discount [0] = not limited to)] [100009] = = Array ([5] = Ar Ray ([name] = Price [8] = 0-29) [6] = = Array ([name] = discount [30 percent-50 percent] + +) [7] = = Array ([name] + press [+] = = Peking University Press) )//array 2Array ([0] = = Array ([attr_id] = 5 [Attr_name] = Price [at Tr_value] = 0-29,30-49,50-99,100 above) [1] = = Array ([attr_id] = 6 [attr_ Name] = Discount [Attr_value] = 00 percent-30 percent, 30 percent-50 percent, 50 percent-70 percent, 70 percent-10 percent) [2] = = Array ([attr_id] = 7 [at Tr_name] + press [Attr_value]//Get Results: Array 3Array ([100008] + = Array ([Price ] = [Discount] = not limited [publisher] = [100009] = = Array ([Price] => ; 0-29 [discount] + 30 percent-50 percent [Publisher] = Peking University Press)
Reply to discussion (solution)
$a = Array (100008 = = Array (5 = = = ' Price ', 0 = ' unlimited ',), 6 = = Array ( ' Name ' = ' Discount ', 0 = ' unlimited ', ', '), 100009 = = Array (5 = = Array (' name ' = ' price '), 8 = ' 0-29 ',), 6 = = Array (' name ' = ' discount ', ' 30 percent-50 percent ', '), 7 = = Array (' Nam E ' = = ' Press ', ' Beijing University Press ',),); $b = Array (0 = = Array (' attr_id ' = ' 5 ', ' attr_name ' = > ' Price ', ' attr_value ' = ' + ' 0-29,30-49,50-99,100 ', ', ' 1 = = Array (' attr_id ' = ' 6 ', ' Attr_name ' =&G T ' Discount ', ' attr_value ' = ' 00 percent-30 percent, 30 percent-50 percent, 50 percent-70 percent, 70 percent-10 percent ', ', ' 2 = ' array (' attr_id ' = ' 7 ', ' attr_name ' = ' + ' Press ', ' attr_value ' = ', '); foreach ($a as $key = = $item) {$t = array (); foreach ($b as $v) {$k = $v [' attr_id ']; $t [$v [' attr_name ']] = Isset ($item [$k])? End ($item [$k]): $v [' Attr_value ']; } $c [$key] = $t;} Print_r ($c);
Array ([ 100008]/= Array ([price] = not limited to [ discount] = [Publisher] = [ 100009] = = Array ( [Price] = 0-29 [discount] = 30 percent-50 percent [publishing house] = = Peking University Press ))
Moderator, cow ....