2014-03-28 91 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