2014-03-28 64 views
0

我在下面有下面的数组,我真的很困难如何将定价数据添加到相应的产品数据,所以我会为每个数字索引都有一个数组。如何组合多维数组?

[Product] => Array 
     (
      [0] => Array 
       (
        [Title] => Rent: Filmed Live on Broadway 
        [UPC] => 043396297913 
        [ASIN] => B001LMAKAG 
        [SalesRank] => 12429 
        [ImageURL] => http://ecx.images-amazon.com/images/I/51rzFLo7EML._SL200_.jpg 
        [ProductGroup] => DVD 
        [Publisher] => Sony Pictures Home Entertainment 
        [NumberOfDiscs] => 1 
       ) 

      [1] => Array 
       (
        [Title] => Scrooged 
        [UPC] => 097363205425 
        [ASIN] => 6305609772 
        [SalesRank] => 308636 
        [ImageURL] => http://ecx.images-amazon.com/images/I/51BqfhI7NaL._SL200_.jpg 
        [ProductGroup] => DVD 
        [Publisher] => Paramount 
        [NumberOfDiscs] => 1 
       ) 

      [2] => Array 
       (
        [Title] => Upstairs Downstairs: Season 2 
        [UPC] => 883929253753 
        [ASIN] => B0090XUARQ 
        [SalesRank] => 23167 
        [ImageURL] => http://ecx.images-amazon.com/images/I/51O-STwE1SL._SL200_.jpg 
        [ProductGroup] => DVD 
        [Publisher] => BBC Home Entertainment 
        [NumberOfDiscs] => 2 
       ) 

      [3] => Array 
       (
        [Title] => Junction Boys 
        [UPC] => 796019795210 
        [ASIN] => B000FVR1T2 
        [SalesRank] => 32220 
        [ImageURL] => http://ecx.images-amazon.com/images/I/41151H2xalL._SL200_.jpg 
        [ProductGroup] => DVD 
        [Publisher] => Genius 
        [NumberOfDiscs] => 1 
       ) 

      [4] => Array 
       (
        [Title] => 20-Film Horror: The Prophecy II/ Dracula III: Legacy/ The House That Would Not Die/ Seedpeople/ The Greenskeeper/ Grim/ Evil Bong 3 & More 
        [UPC] => 096009092443 
        [ASIN] => B008R52L7K 
        [SalesRank] => 26999 
        [ImageURL] => http://ecx.images-amazon.com/images/I/617n-5nMLYL._SL200_.jpg 
        [ProductGroup] => DVD 
        [Publisher] => Echo Bridge Home Entertainment 
        [NumberOfDiscs] => 4 
       ) 

     ) 

    [Pricing] => Array 
     (
      [0] => Array 
       (
        [LowestPrice] => 3.03 
        [ShippingPrice] => 3.99 
        [TotalPrice] => 7.02 
       ) 

      [1] => Array 
       (
        [LowestPrice] => 0.01 
        [ShippingPrice] => 3.99 
        [TotalPrice] => 4 
       ) 

      [2] => Array 
       (
        [LowestPrice] => 22.19 
        [ShippingPrice] => 3.99 
        [TotalPrice] => 26.18 
       ) 

      [3] => Array 
       (
        [LowestPrice] => 1.33 
        [ShippingPrice] => 3.99 
        [TotalPrice] => 5.32 
       ) 

      [4] => Array 
       (
        [LowestPrice] => 0.74 
        [ShippingPrice] => 3.99 
        [TotalPrice] => 4.73 
       ) 

     ) 

) 

任何帮助将不胜感激。

感谢,

埃里克

+1

http://nl1.php.net/array_merge – Companjo

回答

1
for($index=0; $index<=4; $index++){ 
    $final_array[$index] = array_merge($product[$index],$pricing[$index]); 
} 

这将会给你想要的阵列。

+0

非常感谢! – Eric

+0

您也可以通过用值= count($ product)+ 1 – Vagabond

+0

的变量替换数字'4'来提供更大的灵活性谢谢。我做了类似的事情。出于某种原因,我真的很难与合并数组。 – Eric

0

尝试

foreach ($products as $key => $product){ 
    $products[$key] = array_merge($product, $prices[$key]) 
} 
+0

谢谢你的帮助。 – Eric